这个错误困扰了我两天。所以我需要将一个项目从Unity导入android studio,但是给了我这个错误:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\DELL\AppData\Local\Android\sdk\build-tools\23.0.2\dx.bat --dex --no-optimize --output C:\Users\DELL\AndroidStudioProjects\Passingdata1\app\build\intermediates\dex\debug --input-list=C:\Users\DELL\AndroidStudioProjects\Passingdata1\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/king/passingdata/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
我的构建gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.king.passingdata"
minSdkVersion 18
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/myandroidplugin.jar')
compile files('libs/QCARUnityPlayer.jar')
compile files('libs/unity-classes.jar')
compile files('libs/Vuforia.jar')
}
我在stackoverflow和其他网站上看到了很多UNEXPECTED TOP-LEVEL EXCEPTION:
和Error:Execution failed for task ':app:dexDebug'.
,但是它们中没有一个似乎与我的错误相似或对我的情况有帮助。
答案 0 :(得分:1)
在build.gradle文件中尝试在android块中添加以下块。
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries = false
}
您的 defaultConfig 添加此
multiDexEnabled true
defaultConfig {
applicationId "com.example"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
renderscriptTargetApi 21
renderscriptSupportModeEnabled true;
}
在gradle依赖项添加中,
compile' com.android.support:multidex:1.0.1'
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:multidex:1.0.1'
}
在Application类中,attachBaseContext方法包含这一行
MultiDex.install(本);
public class ExampleApp extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
在AndroidManifest.xml文件中,
添加属性"名称"并指定上述申请类别。
<application
android:name="com.ExampleApp">
<!--- Activities -->
</application>
现在尝试在清理后运行项目并构建项目。
希望它会帮助你亲爱的朋友!