构建NDK样本时出现意外的顶级异常

时间:2015-07-19 22:17:47

标签: android android-ndk

我刚刚在GoogleSamples克隆了项目,然后cd到native-activity目录。我打字:

> gradle clean build 

我得到了这个:

Starting process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java''. Working directory: /Users/johndifool/Develop/android/native-activity/app Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java -Xmx1024M -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /Users/johndifool/Develop/android/sdk/build-tools/22.0.1/lib/dx.jar com.android.dx.command.Main --dex --verbose --output /Users/johndifool/Develop/android/native-activity/app/build/intermediates/dex/arm7/debug /Users/johndifool/Develop/android/native-activity/app/build/intermediates/classes/arm7/debug
Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java''
processing /Users/johndifool/Develop/android/native-activity/app/build/intermediates/classes/arm7/debug/./com/example/native_activity/BuildConfig.class...
processing /Users/johndifool/Develop/android/native-activity/app/build/intermediates/classes/arm7/debug/./com/example/native_activity/R$attr.class...
processing /Users/johndifool/Develop/android/native-activity/app/build/intermediates/classes/arm7/debug/./com/example/native_activity/R$string.class...
processing /Users/johndifool/Develop/android/native-activity/app/build/intermediates/classes/arm7/debug/./com/example/native_activity/R.class...


UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
  at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
  at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
  at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
  at com.android.dx.command.dexer.Main.processClass(Main.java:704)
  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
  at com.android.dx.command.dexer.Main.access$300(Main.java:83)
  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
  at com.android.dx.command.dexer.Main.processOne(Main.java:632)
  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
  at com.android.dx.command.dexer.Main.run(Main.java:246)
  at com.android.dx.command.dexer.Main.main(Main.java:215)
  at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/example/native_activity/BuildConfig.class


UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
  at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
  at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
  at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
  at com.android.dx.command.dexer.Main.processClass(Main.java:704)
  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
  at com.android.dx.command.dexer.Main.access$300(Main.java:83)
  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
  at com.android.dx.command.dexer.Main.processOne(Main.java:632)
  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
  at com.android.dx.command.dexer.Main.run(Main.java:246)
  at com.android.dx.command.dexer.Main.main(Main.java:215)
  at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/example/native_activity/R$attr.class


UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
  at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
  at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
  at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
  at com.android.dx.command.dexer.Main.processClass(Main.java:704)
  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
  at com.android.dx.command.dexer.Main.access$300(Main.java:83)
  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
  at com.android.dx.command.dexer.Main.processOne(Main.java:632)
  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
  at com.android.dx.command.dexer.Main.run(Main.java:246)
  at com.android.dx.command.dexer.Main.main(Main.java:215)
  at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/example/native_activity/R$string.class


UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
  at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
  at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
  at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
  at com.android.dx.command.dexer.Main.processClass(Main.java:704)
  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
  at com.android.dx.command.dexer.Main.access$300(Main.java:83)
  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
  at com.android.dx.command.dexer.Main.processOne(Main.java:632)
  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
  at com.android.dx.command.dexer.Main.run(Main.java:246)
  at com.android.dx.command.dexer.Main.main(Main.java:215)
  at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/example/native_activity/R.class

4 errors; aborting

:app:dexArm7Debug FAILED
:app:dexArm7Debug (Thread[main,5,main]) completed. Took 0.219 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexArm7Debug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 22.245 secs
Stopped 0 compiler daemon(s).

我不知道这里发生了什么。我更新到最新的gradle 2.5,它根据项目需要在app脚本中支持'model'。

1 个答案:

答案 0 :(得分:2)

获胜者是...... Java 1.7!

第一行显示我在OSX上使用1.8,这显然打破了构建。对于那些遇到同样问题并因为1.8是最新版本的人,我只是做了:

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

在使用gradle clean build命令

重建之前