我在eclipse中构建我的应用程序没有问题但是一旦我尝试通过ant进行,它就不会构建。我用过“android update project -p”。生成build build.xml和proguard.cfg文件。我试过“ant compile”,它也很好。该应用程序包括一个Android库,如果重要的话有外部库。这里的任何人都是在我尝试“释放”时打印出的错误,
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.ExceptionWithContext
at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:340)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
at com.android.dx.command.dexer.Main.processClass(Main.java:369)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
at com.android.dx.command.dexer.Main.access$400(Main.java:59)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:134)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
at com.android.dx.command.dexer.Main.processOne(Main.java:313)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
at com.android.dx.command.dexer.Main.run(Main.java:185)
at com.android.dx.command.dexer.Main.main(Main.java:166)
at com.android.dx.command.Main.main(Main.java:90)
Caused by: java.lang.NullPointerException
at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:84)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:243)
... 23 more
此刻我非常困惑所以希望有人可以解释一下。
答案 0 :(得分:1)
我认为我对this page的回答也适用于此错误。 当您在死代码中初始化匿名类时会发生这种情况。
解释为什么它只会在发布而不是在调试中发生的原因是在优化时删除了死代码。
答案 1 :(得分:0)
仔细阅读本页:
http://developer.android.com/tools/projects/projects-cmdline.html
您可以尝试以下解决方案之一:
1)单行命令
android update project -p --subprojects
2)更新主项目和库项目的 build.xml 文件:
android update lib-project --path myPath/Lib
android update project --name android_app --path . --library myPath/Lib
1)或2)之后
ant clean
ant release