我正在尝试在命令行模式下使用 ant 构建我的 Android 项目。 它可以与 eclipse 一起使用,并且曾经可以与 ant 一起使用,直到我安装了最新的 android sdk。
我运行ant release -buildfile projectdir\build.xml
。编译过程没问题,对齐apk后,运行时失败,出现ClassDefNotFoundError acra.ACRA
。
我尝试从项目中删除对 acra 的任何引用,但当尝试执行来自库 jar 的任何代码时,它会在运行时失败。
我的 jar 位于项目根目录的 libs
文件夹中。我有点明白这会导致 ant 将它们链接到 apk 中。但事实并非如此。
当我使用以前版本的 android sdk 时,我有一个名为 build.properties
的文件,其属性引用 jars 文件夹external.libs.dir=libs
。但现在我无法再让它工作了,即使我使用新的属性名称 jar.libs.dir=libs
和新的属性文件名称 ant.properties
.
我读到,ClassDefNotFoundError 的原因是在编译时找到了库,但它们没有链接到 apk 中,因此在运行时找不到它们。 请问如何链接 apk 中的外部 jar?
最佳答案
The compilation process is ok, and after aligning the apk, it fails at runtime with ClassDefNotFoundError acra.ACRA
ACRA 中没有 acra.ACRA
类,至少在当前版本中没有。它是org.acra.ACRA
。
My jars are in the libs folder at the root of the project. And I sort of understood this would cause ant to link them into the apk. But it doesn't.
是的,确实如此。然后 ProGuard 正在删除它们,unless you teach ProGuard not to .
关于android - 使用ant构建android项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9933331/