我有一个Android项目,它使用gradle和库项目作为依赖项.Dependency项目与项目具有相同的包名。当我尝试构建项目但失败时。
以下是包含相关文件的文件夹结构:
Library AndroidMainifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:allowBackup="true">
</manifest>
Library build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
enforceUniquePackageName false
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
dexOptions {
preDexLibraries false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Project build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
enforceUniquePackageName false
defaultConfig {
applicationId "com.test"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1"
}
lintOptions {
abortOnError false
}
dexOptions {
preDexLibraries false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':testLib')
}
错误讯息:
Error:Class com.test.BuildConfig has already been added to output. Please remove duplicate copies.
1 error; aborting
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/test/BuildConfig;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:732)
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.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
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)
1 error; aborting
答案 0 :(得分:0)
我认为只有一种方法 - 重命名其中一个包。我尝试在build.gradle中添加'exclude'选项,但尝试不成功。同时,它不是选项,因为您的应用程序需要两个BuildConfig类。