32位的apk 在64位平台上运行不停挂掉的问题

时间:2023-02-04 08:04:19
01-01 00:55:41.800 E/AndroidRuntime(12543): FATAL EXCEPTION: main
01-01 00:55:41.800 E/AndroidRuntime(12543): Process: cn.digirun.update, PID: 12543
01-01 00:55:41.800 E/AndroidRuntime(12543): java.lang.RuntimeException: Unable to instantiate application cn.digirun.update.App: java.lang.ClassNotFoundException: Didn't find class "cn.digirun.update.App" on path: DexPathList[[zip file "/system/priv-app/updateota/updateota.apk"],nativeLibraryDirectories=[/system/priv-app/updateota/lib/arm, /system/priv-app/updateota/updateota.apk!/lib/armeabi, /system/lib, /vendor/lib, /system/vendor/lib, /system/lib, /vendor/lib, /system/vendor/lib]]
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.LoadedApk.makeApplication(LoadedApk.java:807)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5477)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread.-wrap2(ActivityThread.java)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.os.Handler.dispatchMessage(Handler.java:110)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.os.Looper.loop(Looper.java:203)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread.main(ActivityThread.java:6251)
01-01 00:55:41.800 E/AndroidRuntime(12543): at java.lang.reflect.Method.invoke(Native Method)
01-01 00:55:41.800 E/AndroidRuntime(12543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
01-01 00:55:41.800 E/AndroidRuntime(12543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
01-01 00:55:41.800 E/AndroidRuntime(12543): Caused by: java.lang.ClassNotFoundException: Didn't find class "cn.digirun.update.App" on path: DexPathList[[zip file "/system/priv-app/updateota/updateota.apk"],nativeLibraryDirectories=[/system/priv-app/updateota/lib/arm, /system/priv-app/updateota/updateota.apk!/lib/armeabi, /system/lib, /vendor/lib, /system/vendor/lib, /system/lib, /vendor/lib, /system/vendor/lib]]
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-01 00:55:41.800 E/AndroidRuntime(12543): at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
01-01 00:55:41.800 E/AndroidRuntime(12543): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.Instrumentation.newApplication(Instrumentation.java:992)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.LoadedApk.makeApplication(LoadedApk.java:801)
01-01 00:55:41.800 E/AndroidRuntime(12543): ... 9 more
01-01 00:55:41.800 E/AndroidRuntime(12543): Suppressed: java.io.IOException: No original dex files found for dex location /system/priv-app/updateota/updateota.apk
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexFile.openDexFileNative(Native Method)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexFile.openDexFile(DexFile.java:373)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexFile.<init>(DexFile.java:113)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexFile.<init>(DexFile.java:78)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.DexPathList.<init>(DexPathList.java:126)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
01-01 00:55:41.800 E/AndroidRuntime(12543): at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
01-01 00:55:41.800 E/AndroidRuntime(12543): at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:525)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.LoadedApk.getClassLoader(LoadedApk.java:558)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1921)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.LoadedApk.getResources(LoadedApk.java:771)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ContextImpl.<init>(ContextImpl.java:2055)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ContextImpl.createAppContext(ContextImpl.java:2000)
01-01 00:55:41.800 E/AndroidRuntime(12543): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5394)

01-01 00:55:41.800 E/AndroidRuntime(12543): ... 8 more



这里提示Unable to instantiate application cn.digirun.update.App: java.lang.ClassNotFoundException: Didn't find class "cn.digirun.update.App" on path: DexPathList[[zip file "/system/priv-app/updateota/updateota.apk"],nativeLibraryDirectories=[/system/priv-app/updateota/lib/arm, /system/priv-app/updateota/updateota.apk!/lib/armeabi, /system/lib, /vendor/lib, /system/vendor/lib, /system/lib, /vendor/lib, /system/vendor/lib]]

在这些路径中查找应用的相应类时出错


杳看手机的实际情况如下

adb 进入手机的/system/priv-app/updateota/oat目录,发现目录下只有一个arm64。

tpw8735a_t6:/system/priv-app/updateota/oat/arm64 $ ls -l
total 28600
-rw-r--r-- 1 root root 14639824 2017-12-13 02:22 updateota.odex

应用的odex在这个目录里,说明这是一个64位的平台。那按理说,只有在这里来加载类才可以。

但是从上面搜索的路径来看,都是搜索的32位的路径

所以我们需要应用在编译时产生32位的代码和目录。


解决方法:

在应用的Android.mk 中,加入以下语句

LOCAL_MULTILIB := both#同时生成32位和64位的目录和odex


LOCAL_MODULE_TARGET_ARCH:= arm64  #目标CPU架构名。如果为 “arm” 则声称ARM兼容的指令。与CPU架构版本无关。