文章目录
  1. 1. 错误
  2. 2. 原因
  3. 3. 解决
    1. 3.1. Maven
    2. 3.2. Gradle
  4. 4. 总结

错误

Android项目构建时报如下错

1
Error: duplicate files during packaging of APK /Users/snowblink/workspace/NoodlesMobile/app-stu/build/outputs/apk/xxx-debug-unaligned.apk

原因

打包apk文件时,资源文件冲突。

解决

Maven

1
2
3
4
5
6
7
8
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<extractDuplicates>true</extractDuplicates>
</configuration>
</plugin>

Gradle

1
2
3
packagingOptions {
exclude 'META-INF/notice.txt'
}

总结

Android官方文档对构建过程中打包apk的描述

All non-compiled resources (such as images), compiled resources, and the .dex files are sent to the apkbuilder tool to be packaged into an .apk file.

打包apk的过程中构建工具会把所有资源文件拷贝到apk文件中,文件冲突即会报错

文章目录
  1. 1. 错误
  2. 2. 原因
  3. 3. 解决
    1. 3.1. Maven
    2. 3.2. Gradle
  4. 4. 总结
Fork me on GitHub