在集成高德地图demo时候遇到一个奇怪的问题,我是按照官网上的demo完全集成的, 却死活加载不出地图详情,并且抛出如下异常;
01-02 14:36:40.890 19044-19101/duck.mapdemo W/dalvikvm: No implementation found for native Lcom/autonavi/amap/mapcore/MapCore;.nativeNewInstance:(Ljava/lang/String;Ljava/lang/String;)J
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: java.lang.UnsatisfiedLinkError: Native method not found: com.autonavi.amap.mapcore.MapCore.nativeNewInstance:(Ljava/lang/String;Ljava/lang/String;)J
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at com.autonavi.amap.mapcore.MapCore.nativeNewInstance(Native Method)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at com.autonavi.amap.mapcore.MapCore.newMap(MapCore.java:101)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at com.amap.api.mapcore.util.b.C(AMapDelegateImp.java:443)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at com.amap.api.mapcore.util.b.a(AMapDelegateImp.java:133)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at com.amap.api.mapcore.util.b$1.run(AMapDelegateImp.java:340)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
01-02 14:36:40.890 19044-19101/duck.mapdemo W/System.err: at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
百度发现一哥门也跟我遇到同样的问题,他的解决办法是:
对比了一下高德提供的demo 发现少了x86的文件夹,将x86文件夹粘贴到lib目录下运行就好了
正确的解决办法是:打开在APP下的build.gradle文件,在android下加入
task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
完整的build.gradle文件如下:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "duck.mapdemo"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
}