【问题标题】:Multiple dex files define Landroid/support/design/widget/CoordinatorLayout$1;多个dex文件定义 Landroid/support/design/widget/CoordinatorLayout$1;
【发布时间】:2018-03-01 06:07:09
【问题描述】:

每当我想运行我的项目时,我都会收到以下错误

错误:任务执行失败 ':app:transformClassesWithDexForDebug'。 com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:com.android.dex.DexException: 多个dex文件定义 landroid/support/design/widget/CoordinatorLayout$1;

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"
    defaultConfig {
        applicationId "com.example.invinciblesourav.flacom"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"    
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}

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:appcompat-v7:27.+')
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:11.0.4'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
    compile 'com.google.firebase:firebase-core:11.0.4'
    compile 'com.google.firebase:firebase-database:11.0.2'
    compile 'com.google.firebase:firebase-storage:11.0.4'
    compile 'com.android.support:design:25.3.1'
    compile 'com.squareup.picasso:picasso:2.4.0'
    testCompile 'junit:junit:4.12'
}


apply pluenter code heregin: 'com.google.gms.google-services'

请帮助我。我被这个问题困扰了几天。

【问题讨论】:

标签: android


【解决方案1】:

我遇到了完全相同的问题。我通过将每个 Google 支持库更新到最新版本(在编写此解决方案时为 27.1.0)来解决此问题。我还将compileSdkVersion 更新到版本27,将buildToolsVersion 更新到版本27.0.3。我希望这能解决你的问题。

【讨论】:

  • 也为我工作
【解决方案2】:

只需添加 multidex true 并为其添加一个依赖项。 校验码:

defaultConfig {
    ...
    multiDexEnabled true
}

添加依赖:

dependencies {
 compile 'com.android.support:multidex:1.0.1'
}

如果您想详细了解 multidex,请访问以下链接: https://developer.android.com/studio/build/multidex.html

快乐编码...

【讨论】:

  • 错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:android/support/design/widget/CoordinatorLayout$1.class
  • 目标 SDK 版本不应与支持库不同,因此请根据目标 sdk 版本更改 support.design 库版本
  • 并确保 google firebase 依赖项版本上的所有版本都应该相同
  • 现在,它需要一个 gradle 升级。那么,如何实现呢?
【解决方案3】:

我的问题与使用同一库的不同版本有关。我的一个子依赖项引用了不同版本的 com.android.support:design,所以我在 build.gradle 中强制使用了

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
        force 'com.android.support:design:27.1.0'
    }
}

【讨论】:

    【解决方案4】:

    您应该在 build.gradle 文件中启用 multidex 属性

    android {
    
        compileSdkVersion ..
        buildToolsVersion '...'
    
        defaultConfig {
           ...
           targetSdkVersion ..
           multiDexEnabled true  // this line will solve this problem
       }
    }
    

    【讨论】:

      【解决方案5】:

      试试这个...

      apply plugin: 'com.android.application'
      
      android {
      compileSdkVersion 27
      buildToolsVersion "27.0.2"
      defaultConfig {
          applicationId "com.example.invinciblesourav.flacom"
          minSdkVersion 18
          targetSdkVersion 27
          versionCode 1
          versionName "1.0"
      
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
      }
      
      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:appcompat-v7:27.+')
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
      compile 'com.google.firebase:firebase-auth:11.0.4'
      compile 'de.hdodenhof:circleimageview:2.1.0'
      compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
      compile 'com.google.firebase:firebase-core:11.0.4'
      compile 'com.google.firebase:firebase-database:11.0.2'
      compile 'com.google.firebase:firebase-storage:11.0.4'
      compile 'com.android.support:design:25.3.1'
      compile 'com.squareup.picasso:picasso:2.4.0'
      testCompile 'junit:junit:4.12'
      }
      
      
      apply plugin: 'com.google.gms.google-services'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-10
        • 2015-12-06
        • 2014-01-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多