Android cordova 插件:NoClassDefFoundError
Android cordova plugin : NoClassDefFoundError
我的项目是一个 Meteor 应用程序,它有 Web 用户和移动用户(在 Android 和 iOS 上)。我需要使用 Cordova 的本机应用程序的原因是因为我需要使用特定的库(已针对 Android 和 iOS 进行编码)。我开发了一个 cordova-plugin,它是我的 Meteor 应用程序和我的库之间的桥梁。我使用 meteor add cordova:{plugin_name@bitbucket_url/get/commit_hash.tar.gz}
命令添加了这个 cordova-plugin。然后我 运行 我的应用程序 meteor run android-device --verbose
在我的 Nexus 5 上构建它。
当我查看日志时,我没有看到任何错误,我还看到我的插件中需要的 jar 文件被 dexed:
-dex:
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/ant-build/classes
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/CordovaLib/ant-build/classes.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/ant-build/classes.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/anywaresdk.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-async-http-1.4.4.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/libs/google-play-services.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-beacon-library-2.0.jar
[dex] Using Pre-Dexed classes-08b5b91946ca0289c8a6c6185a42d50c.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/CordovaLib/ant-build/classes.jar
[dex] Using Pre-Dexed classes-df56033b7c34d81e6100d180a5eb093f.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/ant-build/classes.jar
[dex] Using Pre-Dexed anywaresdk-ebcd8e8b201f2cf0e8f3947837f0a238.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/anywaresdk.jar
[dex] Using Pre-Dexed android-async-http-1.4.4-1381083dec2d5e09b669d0f4d8aa7dbb.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-async-http-1.4.4.jar
[dex] Using Pre-Dexed google-play-services-63680b630aa52e827ce265766636b8d0.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/libs/google-play-services.jar
[dex] Using Pre-Dexed android-beacon-library-2.0-b9ed313a0085ed5333e28cb89c1128cf.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-beacon-library-2.0.jar
[dex] Found modified input file
[dex] Converting compiled files and external libraries into /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/ant-build/classes.dex...
[dx] Merged dex A (85 defs/107.7KiB) with dex B (207 defs/313.5KiB). Result is 292 defs/511.4KiB. Took 0.3s
[dx] Merged dex A (292 defs/511.4KiB) with dex B (1 defs/0.4KiB). Result is 293 defs/652.5KiB. Took 0.1s
[dx] Merged dex A (293 defs/652.5KiB) with dex B (72 defs/146.9KiB). Result is 365 defs/1077.0KiB. Took 0.1s
[dx] Result compacted from 1634.2KiB to 597.6KiB to save 1036.6KiB
[dx] Merged dex A (365 defs/1077.0KiB) with dex B (40 defs/59.6KiB). Result is 405 defs/597.6KiB. Took 0.2s
[dx] Merged dex A (405 defs/597.6KiB) with dex B (3422 defs/3053.3KiB). Result is 3827 defs/4345.6KiB. Took 0.4s
[dx] Result compacted from 5460.2KiB to 3712.5KiB to save 1747.7KiB
[dx] Merged dex A (3827 defs/4345.6KiB) with dex B (67 defs/95.6KiB). Result is 3894 defs/3712.5KiB. Took 0.6s
但是当我的应用程序在构建后启动时,在执行几秒钟后我收到以下错误:
I/art (18645): Rejecting re-init on previously-failed class java.lang.Class<novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver>
I/art (18645): Rejecting re-init on previously-failed class java.lang.Class<novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver>
D/AndroidRuntime(18645): Shutting down VM
--------- beginning of crash
E/AndroidRuntime(18645): FATAL EXCEPTION: main
E/AndroidRuntime(18645): Process: com.id1yih4vymtz45gm5gsdh, PID: 18645
E/AndroidRuntime(18645): java.lang.NoClassDefFoundError: Failed resolution of: Lnovom/anyware/anywaresdk/AWRAlarmBroadcastReceiver;
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRUtils.cancelAlarm(AWRUtils.java:270)
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRSyncService.stopPushService(AWRSyncService.java:413)
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRSyncService.onDestroy(AWRSyncService.java:420)
E/AndroidRuntime(18645): at android.app.ActivityThread.handleStopService(ActivityThread.java:2894)
E/AndroidRuntime(18645): at android.app.ActivityThread.access00(ActivityThread.java:144)
E/AndroidRuntime(18645): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
E/AndroidRuntime(18645): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(18645): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(18645): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime(18645): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18645): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(18645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime(18645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime(18645): Caused by: java.lang.ClassNotFoundException: Didn't find class "novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.id1yih4vymtz45gm5gsdh-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(18645): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(18645): ... 13 more
E/AndroidRuntime(18645): Suppressed: java.lang.NoClassDefFoundError: novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver
E/AndroidRuntime(18645): at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(18645): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(18645): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(18645): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(18645): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(18645): ... 15 more
E/AndroidRuntime(18645): Suppressed: java.lang.ClassNotFoundException: novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver
E/AndroidRuntime(18645): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(18645): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(18645): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(18645): ... 14 more
E/AndroidRuntime(18645): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我可以看到一些日志,让我知道 anywaresdk.jar
文件中的大部分 class 在 AWRAlarmBroadcastReceiver
发生错误之前已成功使用。为了确保文件存在,我解压缩了 jar 文件,我发现 class 文件应该丢失了...
我还通过 meteor 复制了安装在我的 Nexus 5 中的 apk,将其解压缩并使用 android 构建工具 dexdump
和输出文件 classes.dex
的内容class Lnovom/anyware/anywaresdk/AWRAlarmBroadcastReceiver;
列在其中。
为了确保我的 jar 文件没有损坏或其他什么,我在本机 Android 应用程序中使用了它们,它们按预期工作。
当我通过 Cordova 插件在我的 Meteor 应用程序中使用它们时,为什么会出现 NoClassDefFoundError?
对于任何有类似问题的人,我的问题是这个文件依赖于 support-v4,我没有将它作为依赖项包含在我的 cordova 插件的 plugin.xml
中。感谢 Chris Stratton post
我的项目是一个 Meteor 应用程序,它有 Web 用户和移动用户(在 Android 和 iOS 上)。我需要使用 Cordova 的本机应用程序的原因是因为我需要使用特定的库(已针对 Android 和 iOS 进行编码)。我开发了一个 cordova-plugin,它是我的 Meteor 应用程序和我的库之间的桥梁。我使用 meteor add cordova:{plugin_name@bitbucket_url/get/commit_hash.tar.gz}
命令添加了这个 cordova-plugin。然后我 运行 我的应用程序 meteor run android-device --verbose
在我的 Nexus 5 上构建它。
当我查看日志时,我没有看到任何错误,我还看到我的插件中需要的 jar 文件被 dexed:
-dex:
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/ant-build/classes
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/CordovaLib/ant-build/classes.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/ant-build/classes.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/anywaresdk.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-async-http-1.4.4.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/libs/google-play-services.jar
[dex] input: /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-beacon-library-2.0.jar
[dex] Using Pre-Dexed classes-08b5b91946ca0289c8a6c6185a42d50c.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/CordovaLib/ant-build/classes.jar
[dex] Using Pre-Dexed classes-df56033b7c34d81e6100d180a5eb093f.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/ant-build/classes.jar
[dex] Using Pre-Dexed anywaresdk-ebcd8e8b201f2cf0e8f3947837f0a238.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/anywaresdk.jar
[dex] Using Pre-Dexed android-async-http-1.4.4-1381083dec2d5e09b669d0f4d8aa7dbb.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-async-http-1.4.4.jar
[dex] Using Pre-Dexed google-play-services-63680b630aa52e827ce265766636b8d0.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/com.google.playservices/google-play-services_lib/libs/google-play-services.jar
[dex] Using Pre-Dexed android-beacon-library-2.0-b9ed313a0085ed5333e28cb89c1128cf.jar <- /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/libs/android-beacon-library-2.0.jar
[dex] Found modified input file
[dex] Converting compiled files and external libraries into /home/raphael/WebstormProjects/skyshow/.meteor/local/cordova-build/platforms/android/ant-build/classes.dex...
[dx] Merged dex A (85 defs/107.7KiB) with dex B (207 defs/313.5KiB). Result is 292 defs/511.4KiB. Took 0.3s
[dx] Merged dex A (292 defs/511.4KiB) with dex B (1 defs/0.4KiB). Result is 293 defs/652.5KiB. Took 0.1s
[dx] Merged dex A (293 defs/652.5KiB) with dex B (72 defs/146.9KiB). Result is 365 defs/1077.0KiB. Took 0.1s
[dx] Result compacted from 1634.2KiB to 597.6KiB to save 1036.6KiB
[dx] Merged dex A (365 defs/1077.0KiB) with dex B (40 defs/59.6KiB). Result is 405 defs/597.6KiB. Took 0.2s
[dx] Merged dex A (405 defs/597.6KiB) with dex B (3422 defs/3053.3KiB). Result is 3827 defs/4345.6KiB. Took 0.4s
[dx] Result compacted from 5460.2KiB to 3712.5KiB to save 1747.7KiB
[dx] Merged dex A (3827 defs/4345.6KiB) with dex B (67 defs/95.6KiB). Result is 3894 defs/3712.5KiB. Took 0.6s
但是当我的应用程序在构建后启动时,在执行几秒钟后我收到以下错误:
I/art (18645): Rejecting re-init on previously-failed class java.lang.Class<novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver>
I/art (18645): Rejecting re-init on previously-failed class java.lang.Class<novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver>
D/AndroidRuntime(18645): Shutting down VM
--------- beginning of crash
E/AndroidRuntime(18645): FATAL EXCEPTION: main
E/AndroidRuntime(18645): Process: com.id1yih4vymtz45gm5gsdh, PID: 18645
E/AndroidRuntime(18645): java.lang.NoClassDefFoundError: Failed resolution of: Lnovom/anyware/anywaresdk/AWRAlarmBroadcastReceiver;
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRUtils.cancelAlarm(AWRUtils.java:270)
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRSyncService.stopPushService(AWRSyncService.java:413)
E/AndroidRuntime(18645): at novom.anyware.anywaresdk.AWRSyncService.onDestroy(AWRSyncService.java:420)
E/AndroidRuntime(18645): at android.app.ActivityThread.handleStopService(ActivityThread.java:2894)
E/AndroidRuntime(18645): at android.app.ActivityThread.access00(ActivityThread.java:144)
E/AndroidRuntime(18645): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
E/AndroidRuntime(18645): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(18645): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(18645): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime(18645): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18645): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(18645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime(18645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime(18645): Caused by: java.lang.ClassNotFoundException: Didn't find class "novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.id1yih4vymtz45gm5gsdh-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(18645): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(18645): ... 13 more
E/AndroidRuntime(18645): Suppressed: java.lang.NoClassDefFoundError: novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver
E/AndroidRuntime(18645): at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(18645): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(18645): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(18645): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(18645): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(18645): ... 15 more
E/AndroidRuntime(18645): Suppressed: java.lang.ClassNotFoundException: novom.anyware.anywaresdk.AWRAlarmBroadcastReceiver
E/AndroidRuntime(18645): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(18645): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(18645): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(18645): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(18645): ... 14 more
E/AndroidRuntime(18645): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我可以看到一些日志,让我知道 anywaresdk.jar
文件中的大部分 class 在 AWRAlarmBroadcastReceiver
发生错误之前已成功使用。为了确保文件存在,我解压缩了 jar 文件,我发现 class 文件应该丢失了...
我还通过 meteor 复制了安装在我的 Nexus 5 中的 apk,将其解压缩并使用 android 构建工具 dexdump
和输出文件 classes.dex
的内容class Lnovom/anyware/anywaresdk/AWRAlarmBroadcastReceiver;
列在其中。
为了确保我的 jar 文件没有损坏或其他什么,我在本机 Android 应用程序中使用了它们,它们按预期工作。
当我通过 Cordova 插件在我的 Meteor 应用程序中使用它们时,为什么会出现 NoClassDefFoundError?
对于任何有类似问题的人,我的问题是这个文件依赖于 support-v4,我没有将它作为依赖项包含在我的 cordova 插件的 plugin.xml
中。感谢 Chris Stratton post