意外的顶级异常:android studio 和 andengine 重复 类
UNEXPECTED TOP-LEVEL EXCEPTION: android studio and andengine duplicate classes
我正在使用 Android Studio 和 AndEngine 库以及使用此 link 设置的 TexturePacker 扩展:
Setting Up AndEngine with Android Studio
我遇到了这个问题:
Error:Class org.andengine.BuildConfig has already been added to output. Please remove duplicate copies.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Diego\android-sdks\build-tools.1.2\dx.bat --dex --no-optimize --output C:\Users\Diego\NEXT\Next\app\build\intermediates\dex\debug --input-list=C:\Users\Diego\NEXT\Next\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/andengine/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.access0(Main.java:83)
at com.android.dx.command.dexer.Main.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.M...(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
我什么都试过了。清理项目,删除 BuildConfig 类(它们是在 texturepacker 库中自动创建的),排除模块,重新导入 third_party 库...但似乎没有什么可以解决的。
这是我的 build.gradle 个文件:
应用程序:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.zmaxstudios.next"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile project(':third_party:andengine')
compile project(':third_party:texturepacker')
}
AndEngine > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Texturepacker > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
dependencies {
compile project(':third_party:andengine')
}
如何删除重复的 BuildConfig 文件?或者我应该怎么做才能解决这个问题?
谢谢
您的问题似乎出在您的依赖项上,就我而言是这样的。
compile 'com.google.android.gms:play-services:6.5.87'// and here's the issue
Google Play Services 库可能非常大,当结合许多第三方库或一些较新的 Google 库时,这可能会成为您体验中的冗余。我 运行 在实施 Google 云存储时遇到了类似的问题。通常,我现在只包含 android 支持库中我真正需要的内容,即
compile 'com.google.apis:google-api-services-storage:v1-rev18-1.19.0'
compile 'com.google.http-client:google-http-client-jackson2:1.20.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
compile 'com.google.api-client:google-api-client-java6:1.20.0'
compile 'com.google.android.gms:play-services-maps:7.3.0'
compile 'com.google.android.gms:play-services-location:7.3.0'
你能不能从我在这里看到的依赖项中删除这一行你正在使用两个支持库。清理并构建您的项目
compile 'com.android.support:support-v13:21.0.3'
我终于解决了这个问题,它与支持库无关。我从 third_party 库中得到问题,因为 texturepacker 库的清单文件按照问题中提供的 link 中的步骤具有相同的 andengine 包,所以 BuildConfig.java 类被复制了。现在,清单文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine" >
<application>
</application>
</manifest>
和 texturepacker:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine.extension.texturepacker.opengl.texture.util.texturepacker" >
<application>
</application>
</manifest>
希望对您有所帮助。
感谢大家的回答。
我正在使用 Android Studio 和 AndEngine 库以及使用此 link 设置的 TexturePacker 扩展:
Setting Up AndEngine with Android Studio
我遇到了这个问题:
Error:Class org.andengine.BuildConfig has already been added to output. Please remove duplicate copies.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Diego\android-sdks\build-tools.1.2\dx.bat --dex --no-optimize --output C:\Users\Diego\NEXT\Next\app\build\intermediates\dex\debug --input-list=C:\Users\Diego\NEXT\Next\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/andengine/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.access0(Main.java:83)
at com.android.dx.command.dexer.Main.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.M...(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
我什么都试过了。清理项目,删除 BuildConfig 类(它们是在 texturepacker 库中自动创建的),排除模块,重新导入 third_party 库...但似乎没有什么可以解决的。
这是我的 build.gradle 个文件:
应用程序:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.zmaxstudios.next"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile project(':third_party:andengine')
compile project(':third_party:texturepacker')
}
AndEngine > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Texturepacker > build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
dependencies {
compile project(':third_party:andengine')
}
如何删除重复的 BuildConfig 文件?或者我应该怎么做才能解决这个问题? 谢谢
您的问题似乎出在您的依赖项上,就我而言是这样的。
compile 'com.google.android.gms:play-services:6.5.87'// and here's the issue
Google Play Services 库可能非常大,当结合许多第三方库或一些较新的 Google 库时,这可能会成为您体验中的冗余。我 运行 在实施 Google 云存储时遇到了类似的问题。通常,我现在只包含 android 支持库中我真正需要的内容,即
compile 'com.google.apis:google-api-services-storage:v1-rev18-1.19.0'
compile 'com.google.http-client:google-http-client-jackson2:1.20.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
compile 'com.google.api-client:google-api-client-java6:1.20.0'
compile 'com.google.android.gms:play-services-maps:7.3.0'
compile 'com.google.android.gms:play-services-location:7.3.0'
你能不能从我在这里看到的依赖项中删除这一行你正在使用两个支持库。清理并构建您的项目
compile 'com.android.support:support-v13:21.0.3'
我终于解决了这个问题,它与支持库无关。我从 third_party 库中得到问题,因为 texturepacker 库的清单文件按照问题中提供的 link 中的步骤具有相同的 andengine 包,所以 BuildConfig.java 类被复制了。现在,清单文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine" >
<application>
</application>
</manifest>
和 texturepacker:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andengine.extension.texturepacker.opengl.texture.util.texturepacker" >
<application>
</application>
</manifest>
希望对您有所帮助。
感谢大家的回答。