java - 将用Java编写的.jar导入Android,noClassDefFoundError

标签 java android noclassdeffounderror

我正在开发一个基于 android 的小型项目(我是该系统的新手)。当我在 Android 模拟器上运行代码时,它崩溃了,我得到了 noClassDefFoundError。我要导入的 .jar 是一个非常简单的类,编写为 Java 项目。错误不是 Android 依赖项或“lib/libs”。

.jars(我从 dropboxAPI 导入)工作正常(在直接获取依赖项之后),但同样的修复不适用于我的 .jar。

有人知道我做错了什么吗?

// S verker

[2012-11-22 20:25:58 - DropDoList] Android Launch!
[2012-11-22 20:25:58 - DropDoList] adb is running normally.
[2012-11-22 20:25:58 - DropDoList] Performing com.example.dropdolist.DropDoList activity launch
[2012-11-22 20:25:58 - DropDoList] Automatic Target Mode: using existing emulator    'emulator-5554' running compatible AVD 'Galaxy2v3'
[2012-11-22 20:25:58 - DropDoList] WARNING: Application does not specify an API level requirement!
[2012-11-22 20:25:58 - DropDoList] Device API version is 16 (Android 4.1.2)
[2012-11-22 20:25:58 - DropDoList] Uploading DropDoList.apk onto device 'emulator-5554'
[2012-11-22 20:26:02 - DropDoList] Installing DropDoList.apk...
[2012-11-22 20:26:11 - DropDoList] Success!
[2012-11-22 20:26:11 - DropDoList] Starting activity com.example.dropdolist.DropDoList on device emulator-5554
[2012-11-22 20:26:12 - DropDoList] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]  cmp=com.example.dropdolist/.DropDoList }
[2012-11-22 20:41:10 - DropDoList] Dx 
trouble processing:
[2012-11-22 20:41:10 - DropDoList] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing Tester/Transaction.class
...while processing Tester/Transaction.class
[2012-11-22 20:41:10 - DropDoList] Dx 
trouble processing:
[2012-11-22 20:41:10 - DropDoList] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing test/Tester.class
...while processing test/Tester.class
[2012-11-22 20:41:10 - DropDoList] Dx 2 warnings

最佳答案

您的两个类的 Dx 错误类文件魔法 (cafebabe) 或版本。此错误不会停止构建过程。相反,它会默默地从最终编译的 apk 中排除这些文件。

如果您使用(比方说)Java 5 并且您使用的是用 Java 6 编译的 JAR,则会出现此错误。

最简单的解决方法是将您的 Java 版本升级到 JAR 使用的版本。您可以通过转到 Project -> Properties -> Java Compiler 并选中 Enable project specific settings 框并更改 Compiler compliance level 来更改用于构建的版本: 值。

Android 工具不能很好地与 Java 7 配合使用,并且在使用 Java 5 时会出现大量 @Override 错误,因此我建议使用 Java 6(在 Java 中为 1.6编译器合规性下拉列表)。如果它不存在,您可能需要重新安装它。

关于java - 将用Java编写的.jar导入Android,noClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13519041/

相关文章:

java - 有什么理由不将 invokevirtual 和 invokeinteface 字节码指令合二为一吗?

java - Android布局-如何在矩形上画一个洞

android - Android 的编码风格标准

android - java.lang.NoClassDefFoundError : android. 部件.ListPopupWindow

spring - java.lang.NoClassDefFoundError : org/apache/commons/pool2/PooledObjectFactory

java - 我想打印 hi GrandFather;但它似乎打印 hi Father

java - Jax-WS 接口(interface)作为参数

android - Gson 自定义反序列化器就在现场

清除 RAM 内存时 Android 应用程序崩溃

java - Android 构建返回 "java.lang.NoClassDefFoundError: com/android/tools/lint/LintCliClient"