任务的Android Studio 3.0执行失败:无法合并dex

Ang*_*raj 67 android build-error android-studio-3.0

android studio在构建执行时出现构建错误,其中包含以下"错误:执行任务失败":app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex"

我的app:build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.pdroid.foodieschoice"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.firebaseui:firebase-ui-auth:2.3.0'

    testCompile 'junit:junit:4.12'
}
configurations.all {
    resolutionStrategy {
        force 'com.android.support:appcompat-v7:26.0.1'
        force 'com.android.support:support-compat:26.0.1'
        force 'com.android.support:support-core-ui:26.0.1'
        force 'com.android.support:support-annotations:26.0.1'
        force 'com.android.support:recyclerview-v7:26.0.1'
    }
}

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

任何解决方案

编辑:我已经通过firebase github网站完成了样本并解决了

sul*_*man 59

对于基于Cordova的项目,cordova clean android再次在构建之前运行,如@mkimmet建议的那样.

  • 对我来说,安装“cordova-plugin-androidx”和“cordova-plugin-androidx-adapter”解决了问题 (2认同)

Nia*_*shi 45

添加可能与您的兼容的外部库时会发生此错误compileSdkVersion.

添加时要小心external library.

我花了2天时间解决这个问题,最后按照这些步骤解决了问题.

  • 确保您所有的支持库是一样compileSdkVersion的你build.gradle(Module:app)在我的情况下,它是26.在此输入图像描述

  • 在defaultConfig类别中,键入multiDexEnabled true.这是重要的部分.multiDexEnabled真实图像

  • 转到文件 | 设置 | 构建,执行,部署 | 即时运行,并尝试启用/禁用即时运行热插拔...,然后单击 启用即时运行热插拔...图像

  • Sync 你的项目.

  • 最后,转到Build | 点击Rebuild Project.

  • 注意:重建项目首先清理然后构建项目.


Ish*_*ndo 31

尝试在gradle中添加它

    android {
      defaultConfig {
        multiDexEnabled true
        }
   }
Run Code Online (Sandbox Code Playgroud)


小智 20

只需尝试"构建 - >清洁项目".这解决了我的问题.

  • 感谢这在Ionic/Cordova项目中通过运行*cordova clean android*为我工作,同时我还安装了cordova-android-support-gradle-release插件. (5认同)
  • 你不觉得我们没试过吗? (2认同)

Mod*_*era 16

解析度:

请参阅此链接:由于有多种选项可根据minSdkVersion来关闭警告,因此将其设置为20以下

 android {
     defaultConfig {
         ...
         minSdkVersion 15 
         targetSdkVersion 26
         multiDexEnabled true
     }
     ... }

 dependencies {   compile 'com.android.support:multidex:1.0.3' }
Run Code Online (Sandbox Code Playgroud)

如果您的build.gradle集合中的minSdkVersion大于20,请使用以下命令关闭警告:

  android {
      defaultConfig {
          ...
          minSdkVersion 21 
          targetSdkVersion 26
          multiDexEnabled true
      }
      ... }
Run Code Online (Sandbox Code Playgroud)

更新依赖关系,如下所示:

     dependencies {
        implementation 'com.android.support:multidex:1.0.3'
     }
Run Code Online (Sandbox Code Playgroud)

同样,唯一的区别是依赖项中的关键字:

minSdkVersion低于20:使用编译

minSdkVersion 20以上:使用实现

  1. 希望这对您有所帮助,如果解决了您的问题,请提出反对意见,谢谢。
  2. 也为更多的信息,关于为什么会发生,请阅读链接中的第一款,它会彻底解释为什么?并且请问这个警告的意思。


Md *_*san 6

对我来说,补充一下

multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)

packagingOptions {
        exclude 'META-INF/NOTICE' 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }
Run Code Online (Sandbox Code Playgroud)

进入应用程序级别Build.gradle文件解决了这个问题


Mah*_*ahi 6

转到您的模块级build.gradle文件并将以下几行添加到代码中

    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)

这样就轻松解决了问题。检查此文档