初始化百度地图SDK时出现UnsatisfiedLinkError

Posted

技术标签:

【中文标题】初始化百度地图SDK时出现UnsatisfiedLinkError【英文标题】:UnsatisfiedLinkError while initializing Baidu Map SDK 【发布时间】:2018-03-26 19:38:40 【问题描述】:

我正在尝试将百度地图 SDK 集成到我的 android 应用程序中。

库的结构:

导致此代码出现问题:

SDKInitializer.initialize(applicationContext)

错误日志:

    03-27 00:57:26.557 18050-18050/com.emerson.oversight E/NativeLoader: found libBaiduMapSDK_base_v4_5_2.so error
03-27 00:57:26.558 18050-18050/com.emerson.oversight E/art: No implementation found for int com.baidu.platform.comjni.tools.JNITools.initClass(java.lang.Object, int) (tried Java_com_baidu_platform_comjni_tools_JNITools_initClass and Java_com_baidu_platform_comjni_tools_JNITools_initClass__Ljava_lang_Object_2I)
03-27 00:57:26.560 18050-18050/com.emerson.oversight D/AndroidRuntime: Shutting down VM


    --------- beginning of crash
03-27 00:57:26.562 18050-18050/com.emerson.oversight E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.emerson.oversight, PID: 18050
    java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.platform.comjni.tools.JNITools.initClass(java.lang.Object, int) (tried Java_com_baidu_platform_comjni_tools_JNITools_initClass and Java_com_baidu_platform_comjni_tools_JNITools_initClass__Ljava_lang_Object_2I)
        at com.baidu.platform.comjni.tools.JNITools.initClass(Native Method)
        at com.baidu.platform.comjni.tools.a.b(Unknown Source)
        at com.baidu.platform.comapi.a.<clinit>(Unknown Source)
        at com.baidu.platform.comapi.a.a(Unknown Source)
        at com.baidu.platform.comapi.c.a(Unknown Source)
        at com.baidu.mapapi.SDKInitializer.initialize(Unknown Source)
        at com.baidu.mapapi.SDKInitializer.initialize(Unknown Source)
        at oversight.controller.ui.activities.BaiduMapActivity.onCreate(BaiduMapActivity.kt:84)
        at android.app.Activity.performCreate(Activity.java:6977)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6823)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
lll

【问题讨论】:

发布您的onCreate 方法和您的build.gradle 这是我的onCreate ``` @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); SDKInitializer.initialize(this.getApplicationContext()); SDKInitializer.setCoordType(CoordType.BD09LL); ``` 你能解决这个问题吗,如果是,请分享你的解决方案给我,因为我在创建签名发布 apk 时也遇到了同样的问题 【参考方案1】:

应用级别(不是顶层)的build.gradle 文件应该是:

apply plugin: 'com.android.application'

repositories 
    flatDir 
        dir 'libs'
    


android 

    // Stuff ...

    sourceSets 
        main 
            jniLibs.srcDir 'libs'
        
    

   // Stuff ...


dependencies 

    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Stuff..

【讨论】:

以上是关于初始化百度地图SDK时出现UnsatisfiedLinkError的主要内容,如果未能解决你的问题,请参考以下文章

百度地图sdk踩坑之旅

尝试初始化 iOS AppsFlyer SDK 时出现 SIGABRT 错误

百度定位SDK的使用示例

iframe嵌入高德地图出现崩溃

android 百度地图系列之地图初始化及定位

如何注册和获取百度地图的密钥