使用ant发布android包时编译错误

时间:2014-07-29 09:38:46

标签: java android ant

我的Android项目有两个外部库:A和B.使用Ant命令行编译Android项目,我遇到了下面的错误。图书馆A的路径为D:\Workspace\library

我将Project A标记为project.properties文件中的库,该文件来自the post。但是,它仍然没有成功。显然,编译不会将项目A视为库,而是需要classes.dex文件。

还有其他建议吗?

错误:

[dex] Converting compiled files and external libraries into d:\apk\compile\classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.io.FileNotFoundException: D:\Workspace\library\bin\classes.jar (系统找不到指定的文件。)
       [dx]     at java.util.zip.ZipFile.open(Native Method)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:596)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
       [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:230)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:199)
       [dx]     at com.android.dx.command.Main.main(Main.java:103)
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.io.FileNotFoundException: D:\Workspace\YimianBaseLib\bin\classes.jar (系统找不到指定的文件。)
       [dx]     at java.util.zip.ZipFile.open(Native Method)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at java.util.zip.ZipFile.<init>(Unknown Source)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:596)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
       [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:230)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:199)
       [dx]     at com.android.dx.command.Main.main(Main.java:103)
       [dx] 2 errors; aborting

1 个答案:

答案 0 :(得分:0)

这个错误的根本原因是这两个lib项目不被视为一个库,尽管它们两个明显地被注意为&#34; android.library = true&#34;在project.properties中(我在这里很困惑但很确定我会把它标记为lib。)对于Ant的编译机制,它会使jar文件具有不同的名称,但具有相同的内容,具体取决于是否或者它不是一个lib

  1. 对于非库项目,它将是$ {project_name} .jar
  2. 对于图书馆项目,它将是classes.jar
  3. 编译主项目时,Ant需要将classes.jar作为其依赖项的输入来生成最终包。所以这个过程停在这里。我必须使用一个愚蠢的解决方案来解决它:lib项目的发布后,我将$ {project_name} .jar重命名为classes.jar并将其解决。