【问题标题】:Unity Gradle Build Failed. DexException: Multiple dex files defineUnity Gradle 构建失败。 DexException: 多个 dex 文件定义
【发布时间】:2018-09-01 11:06:44
【问题描述】:

我想制作一个显示 Admob 横幅广告的 Unity 应用。所以,在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 &lt;meta-data&gt; element at AndroidManifest.xml:23:9-25:38 to override.,所以我添加了以下代码。

资产/插件/Android/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 unity3d android-gradle-plugin admob


    【解决方案1】:

    我解决了这个错误: 服务 -> 广告 -> 高级 -> 取消选中:启用内置广告扩展。

    学分:https://forum.unity.com/threads/android-build-multiple-dex-files-error-multiple-dex-files-define-lcom-google-unity-buildconfig.542843/

    【讨论】:

      【解决方案2】:

      在 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-classes.jar”吗?我将 "classes.jar" 替换为 "unity-classes.jar" 并添加我的 build.gradle 你的代码,但发生了与我上面提到的相同的错误。
      【解决方案3】:

      最后我自己解决了这个错误。就我而言,以下解决方案有效。

      1. Unity > 文件 > 构建设置 > 导出
      2. 在 Android 项目中,删除库中的所有 .jar 和 .aar,除了 unity-classes.jar 和 NcmbGcmPlugins.arr.
      3. 编辑 build.gradle
      4. 运行

      这是 build.gradle(应用级别)

      // 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'
          }
          // ...
      }
      

      【讨论】:

      • 构建设置中的导出选项在哪里
      【解决方案4】:

      从统一论坛找到适合我的解决方案。将构建系统从 Gradle 更改为内部

      参考https://forum.unity.com/threads/android-build-multiple-dex-files-error-multiple-dex-files-define-lcom-google-unity-buildconfig.542843/

      来自 sRn " 嘿, 我希望这是 Unity 错误,并且会在某个时候得到解决,因为我在将项目更新到 2018.2.1f1 Unity 版本后开始收到此错误。 要修复它,您可以尝试启用 Multidex,但在我这样做之后,我遇到了另一个问题,所以我不再打扰并返回 2018.1.x - 这对我来说很好。 您也可以将 Build System 从 Gradle 更改为 Internal(在 File->Build Settings -> Build System 中),这对我也有用,但我想留在 Gradle 以获得更多控制权,所以返回更有意义到 2018.1。 "

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-07
        • 1970-01-01
        • 2014-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多