【问题标题】:Ant build for Android app fails with duplicate res file errorAnt 构建 Android 应用程序失败并出现重复的 res 文件错误
【发布时间】:2013-12-14 01:23:23
【问题描述】:

一段时间以来,我一直在使用 Eclipse 导出创建我的应用程序 .apk,但我现在想使用 ant 进行构建,以便我可以自定义该过程。根据其他地方的建议,我使用“android create project”命令在临时项目中生成合适的 build.xml 文件(然后对其进行修改)。

当我构建时,它在打包步骤中失败并出现重复文件错误:

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating MyApp-debug-unaligned.apk and signing it with a debug key...
[apkbuilder] Found duplicate file for APK: res/drawable-mdpi/icon.png
[apkbuilder] Origin 1: /home/chris/temp/MyApp/MyApp.ap_
[apkbuilder] Origin 2: /home/chris/git/MyApp/MyApp/res/drawable-mdpi/icon.png
...
 /home/chris/android-sdk-linux_x86/tools/ant/build.xml:310: com.android.sdklib.build.DuplicateFileException: Duplicate files at the same path inside the APK

我的蚂蚁属性是:

source.dir=/home/chris/git/MyApp/MyApp
out.dir=/home/chris/temp/MyApp

这似乎是 res 目录的内容与构建期间创建的中间 .ap_ 资源包文件之间的冲突。我不明白为什么包装会包含来自这两个来源的内容,因为重复似乎是不可避免的结果。

我最初认为问题是由 res 子目录(drawable-hdpi、drawable-ldpi、drawable-mdpi)引起的,它们都包含同名文件(icon.png),但我尝试以不同的方式命名这些文件并出现错误仍然发生。在任何情况下,Eclipse 导出构建都可以毫无问题地处理它们。

这个问题看起来很相似 Android aapt duplicate files error when building with ant 但在这种情况下,该人正在创建自己的 build.xml,而我使用的是 android sdk 中提供的那个。

任何帮助将不胜感激。

【问题讨论】:

    标签: java android xml eclipse ant


    【解决方案1】:

    我最终发现了导致问题的原因,尽管不一定是原因。

    在ant.properties中,

    source.dir=/home/chris/git/MyApp/MyApp
    

    应该是

    source.dir=/home/chris/git/MyApp/MyApp/src
    

    我只创建了 ant.properties,因为该项目受 git 控制,并且我认为我需要指定输入的位置,因为它不在正常位置(在工作空间内)。事实证明我不需要这样做,因为构建足够智能,可以从其他属性中解决它。

    我提供了这个,以防其他人遇到同样的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      相关资源
      最近更新 更多