Unity Gradle Build失败。 DexException:多个dex文件定义
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity Gradle Build失败。 DexException:多个dex文件定义相关的知识,希望对你有一定的参考价值。
我想创建一个Unity应用程序,显示Admob的横幅广告。所以,在this之后,我添加了Admob Unity插件。但是,构建时会发生以下错误。
这是控制台:
CommandInvokationFailure: Gradle build failed.
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/PlaybackEngines/androidPlayer/Tools/gradle/lib/gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
/Users/yuukimatsushima/work/unity/BreakPlates2/Temp/gradleOut/src/main/AndroidManifest.xml:25:13-35 Error:
Attribute meta-data#android.support.VERSION@value value=(26.1.0) from [:com.android.support.customtabs-26.1.0:] AndroidManifest.xml:25:13-35
is also present at [:support-compat-26.0.2:] AndroidManifest.xml:28:13-35 value=(26.0.2).
Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':processReleaseManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.1.0) from [:com.android.support.customtabs-26.1.0:] AndroidManifest.xml:25:13-35
is also present at [:support-compat-26.0.2:] AndroidManifest.xml:28:13-35 value=(26.0.2).
Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override.
...
上面的日志说add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override.
,所以我添加以下代码。
资产/插件/安卓/ AndroidManifest.xml中:
<manifest>
<application>
...
<meta-data
tools:replace="android:value"
android:name="android.support.VERSION"
android:value="26.0.2" />
</application>
</manifest>
然后上面的错误已经解决。但是,会发生以下错误。
这是控制台:
CommandInvokationFailure: Gradle build failed.
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zzd;
...
请告诉我如何解决此错误。提前致谢。
注意:Unity版本:版本2018.2.6f1个人
检查Android studio中的外部库,并添加此代码的build.gradle设置
implementation fileTree(include: ['*.jar'], dir: 'libs', exclude: ['classes.jar'])
compileOnly files('libs/classes.jar')
(classes.jar是文件名包括com / google / android / gms / common / api / zzd)
最后我自己解决了这个错误。就我而言,以下解决方案有效。
- Unity>文件>构建设置>导出
- 在Android项目中,除了unity-classes.jar和NcmbGcmPlugins.arr之外,删除libs中的所有.jar和.aar。
- 编辑build.gradle
- 跑
这是build.gradle(app level)
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
// EDIT: added following 3 lines.
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'NcmbGcmPlugin', ext:'aar')
// implementation(name: 'android.arch.lifecycle.runtime-1.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.customtabs-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-compat-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-core-ui-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-core-utils-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-fragment-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-media-compat-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.android.support.support-v4-26.1.0', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-ads-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-ads-base-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-ads-identifier-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-ads-lite-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-basement-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'com.google.android.gms.play-services-gass-15.0.1', ext:'aar') // EDIT: removed
// implementation(name: 'play-services-base-11.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'play-services-basement-11.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'play-services-gcm-11.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'play-services-iid-11.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'play-services-tasks-11.0.0', ext:'aar') // EDIT: removed
// implementation(name: 'support-compat-26.0.2', ext:'aar') // EDIT: removed
// implementation(name: 'support-core-utils-26.0.2', ext:'aar') // EDIT: removed
// implementation(name: 'support-v4-26.0.2', ext:'aar') // EDIT: removed
implementation 'com.android.support:support-v4:26.1.0' // EDIT: added
implementation 'com.google.android.gms:play-services-ads:15.0.1' // EDIT: added
implementation project(':GoogleMobileAdsPlugin')
implementation project(':unity-android-resources')
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
applicationId 'blue.macho.breakplates2'
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
versionCode 1
versionName '1.0'
}
// ...
}
从团结论坛找到适合我的解决方案。将构建系统从Gradle更改为Internal
从sRn开始“嘿,我希望这是Unity的错误,并且会在某些时候得到解决,因为我在将项目更新到2018.2.1f1 Unity版本后开始出现此错误。要解决此问题,您可以尝试启用Multidex,但之后我这样做了,我又遇到了另一个问题,所以我不再烦恼了,回到了2018.1.x - 这对我来说很好。你也可以把Build System从Gradle改为Internal(在File-> Build Settings中 - > Build System),对我来说也很有用,但我想和Gradle保持更多的控制权,所以回到2018.1更有意义。“
我通过以下方式解决了错误:服务 - >广告 - >高级 - >取消选中:启用内置广告扩展程序。
以上是关于Unity Gradle Build失败。 DexException:多个dex文件定义的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Unity 上修复“Gradle Build Failed”?
Gradle 同步失败:'com.android.build.gradle.BasePlugin' 没有实现插件接口