GeorgeYang'Blog

my technology blog

高德地图V3.3.2在非arm64-v8a,armeabi的CPU架构手机上运行奔溃的问题

阅读:703 创建时间:16-06-17 01:46:42 tags:android,RecyclerView

aMap高德地图,AMap_3DMap_V3.3.2_20160525.jar,官方提供的so包只有两种:arm64-v8a,armeabi,也就是说除了arm64-v8a,armeabi两种cpu架构,其他CPU架构的手机显示高德地图都会奔溃:

 java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file 
 ...
 couldn't find "libgdinamapv4sdk752.so"
 at java.lang.Runtime.loadLibrary(Runtime.java:367)
 at java.lang.System.loadLibrary(System.java:1076)
 at com.autonavi.amap.mapcore.MapCore.(MapCore.java:60)
 at com.amap.api.mapcore.AMapDelegateImp.(AMapDelegateImp.java:291)
 at com.amap.api.mapcore.j.(AMapGLSurfaceView.java:23)
 at com.amap.api.mapcore.j.(AMapGLSurfaceView.java:17)
 at com.amap.api.mapcore.as.a(MapFragmentDelegateImp.java:137)
 at com.amap.api.maps.MapView.onCreate(MapView.java:121)

在我的magicbox(插件及而修复集一身的app)项目中,有一个方法 https://github.com/georgeyang1024/magicbox/blob/master/app/src/main/java/online/magicbox/app/PluginContext.java 在这段代码中:

 //释放so文件
         String libPath = getFilesDir().getAbsolutePath() + "/lib/" + packageName + "_" + version;

        plugClassLoder = PlugClassLoder.plugClassLoderCache.get(dexPath);
        if (plugClassLoder==null) {
            ZipInputStream zipIn = null;
            int readedBytes = 0;
            byte buf[] = new byte[4096];
            new File(libPath).mkdirs();
            try {
                zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(dexPath)));
                ZipEntry zipEntry = null;
                while ((zipEntry = zipIn.getNextEntry()) != null) {
                    String name = zipEntry.getName();
                    if (!TextUtils.isEmpty(name)) {
                        if (name.startsWith("lib/" + Build.CPU_ABI + "/")) {
                            String fileName = name.substring(name.lastIndexOf("/")+1,name.length());
                            try {
                                FileOutputStream fileOut = new FileOutputStream(new File(libPath,fileName));
                                while ((readedBytes = zipIn.read(buf)) > 0) {
                                    fileOut.write(buf, 0, readedBytes);
                                }
                                fileOut.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                zipIn.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    zipIn.closeEntry();
                } catch (Exception e) {
                }
            }
            plugClassLoder = new PlugClassLoder(dexPath,context.getCacheDir().getAbsolutePath(),libPath,context.getClassLoader());
        }
    }

可见,apk文件中,只需要提取Build.CPU_ABI对应的so文件,所以非手机的so文件都是无法使用的,如果你的项目使用这个版本的高德地图,有几个对策:

  1. 等待官方提供其他cpu架构的so文件
  2. 改为其他地图sdk(百度地图支持度比较好)
  3. 判断兼容性,所其他操作:
             if (Build.CPU_ABI.equals("armeabi") || Build.CPU_ABI.equals("arm64-v8a")) {
            //支持高德地图
             } else {
            //不支持高德地图
             }