Android Studio 项目中集成百度地图SDK报以下错误:
java.lang.UnsatisfiedLinkError: Native method not found: com.baidu.platform.comjni.map.commonmemcache.JNICommonMemCache.Create)I
at com.baidu.platform.comjni.map.commonmemcache.JNICommonMemCache.Create(Native Method)
at com.baidu.platform.comjni.map.commonmemcache.a.a(Unknown Source)
at com.baidu.platform.comapi.c.c.b(Unknown Source)
at com.baidu.mapapi.a.c(Unknown Source)
at com.baidu.mapapi.SDKInitializer.initialize(Unknown Source)
at com.baidu.mapapi.SDKInitializer.initialize(Unknown Source)
…………
这个问题是由于JNI找不到方法,一般我们是用Eclipse开发,放在libs/armeabi 目录下即可,但是Android studio 的目录不同,用AndroidStudio的话 .so 文件要放在src/main/jniLibs/armeabi 下面。
或者做以下修改(推荐):
在build.gradle文件中android下增加以下代码:
sourceSets{
main{
jniLibs.srcDir(['libs'])
}
}
完整配置文件如下:
apply plugin: 'com.android.library' android {
compileSdkVersion 22
buildToolsVersion "22.0.1" defaultConfig {
minSdkVersion 9
targetSdkVersion "android.os.Build.VERSION_CODES.LOLLIPOP_MR1"
versionCode 100
versionName "1.0"
} buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// 移除lint检查的error
lintOptions {
abortOnError false
} packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
} dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-support-v4.jar')
compile files('libs/BaiduLBS_Android.jar')
compile files('libs/zxing.jar')
}
OK,搞定。