NoClassDefFoundError 在运行时,但类在 classes.dex 中,什么给出了? [英] NoClassDefFoundError at runtime but class is in classes.dex, what givies?

查看:24
本文介绍了NoClassDefFoundError 在运行时,但类在 classes.dex 中,什么给出了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含了一个从 Eclipse Android 项目构建的 JAR 文件,我在我的 Android Studio 项目中引用它,如下所示:

I have included a JAR file built from an Eclipse Android project, and I am referencing it in my Android Studio project like the following:

  compile files('libs/libraryproject.jar')

这有效,而且我能够自动完成代码引用.当我编译 APK 时一切正常.我安装并运行,然后收到 no class def 错误:

This works, and I am able to get auto-complete on code references. When I compile the APK everything is fine. I install and run, and then receive a no class def error:

 java.lang.NoClassDefFoundError: com.android.canvas.CanvasContainer
            at com.app.MainActivity.onCreate(MainActivity.java:22)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

然而,当我解压 APK,并使用 dexdump 查看 classes.dex 文件时,我看到上面的类存在于那里.

However, when I unzip the APK, and use dexdump to view the classes.dex file, I see that the above class exists there.

那为什么我会在运行时收到找不到这个类的错误?

Why then am I getting this class not found error at runtime?

更新:

感谢 Chris 的建议,我注意到在日志的早期,我的 CanvasContainer 类无法链接,因为它无法解析 interface 1990 'Lorg/cocos2dx/lib/Cocos2dxHelper$Cocos2dxHelperListener;'.很明显,我的 Cocos 库代码似乎没有作为 JAR 的一部分导出.

Thanks to Chris's suggestion I noticed that earlier in the logs, my CanvasContainer class could not be linked due to it not being able to resolve interface 1990 'Lorg/cocos2dx/lib/Cocos2dxHelper$Cocos2dxHelperListener;'. Pretty apparently it looks like my Cocos library code is not getting exported as part of my JAR.

推荐答案

在运行时无法满足依赖的类通常会在安装、dex 优化或类似的准备过程中被删除.

A class with dependencies which cannot be met at runtime will usually be dropped during installation, dex optimization or similar preparatory process.

如果您卸载应用程序,启动一些收集所有logcat的东西然后重新安装它,您可能会通过搜索结果发现在安装/准备过程中生成的日志中提到了隐藏的问题.

If you uninstall the app, start up something collecting all of logcat and then install it again, you may find by searching through the result that there is mention of the issue buried in the logs generated during the installation/preparation process.

在此特定情况下,对问题的编辑表明缺少的类本身具有这种类型的未满足的依赖项.

In this specific case here, an edit to the question indicates that the missing class itself had this type of unsatisfied dependency.

这篇关于NoClassDefFoundError 在运行时,但类在 classes.dex 中,什么给出了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆