【问题标题】:Android Studio APK build error - Multiple dex files define Landroid/support/v4/Android Studio APK 构建错误 - 多个 dex 文件定义 Landroid/support/v4/
【发布时间】:2018-05-15 18:36:28
【问题描述】:

//错误:任务':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 /v4/accessibilityservice/AccessibilityServiceInfoCompat;

  apply plugin: 'com.android.application'

      android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
    applicationId "com.cpsraozan.admission"
    minSdkVersion 15
    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'
    }
    }

     }

       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'
      testCompile 'junit:junit:4.12'
      compile 'com.google.firebase:firebase-messaging:9.4.0'
                compile 'com.google.firebase:firebase-core:9.4.0'

       }
      apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 欢迎来到 StackOverflow!如果您在帖子中有特定问题,它可以帮助其他用户帮助您。
  • 有没有人可以帮我..??
  • 你有什么问题?如果您没有真正提出问题,我们将无法帮助您。

标签: android


【解决方案1】:

转到您的 build.gradle 文件并在 defaultConfig 上添加 multidexEnable true。

android {

    compileSdkVersion 26

    defaultConfig {
       targetSdkVersion ..
       multiDexEnabled true  //add this
   }
}

更多信息See this

【讨论】:

  • 试试这些答案。 this
  • 也可以试试this
【解决方案2】:

这有点不直接。您很可能添加了一个新的依赖项或更新了一个依赖项,这导致同一库的多个版本被添加为依赖项。

  1. 检查 Android Studio 是否为此突出显示任何行,尤其是在 Gradle 文件中。

  2. 使用命令运行 Gradle 正在处理的所有依赖项的转储

    ./gradlew -q dependencies app:dependencies

检查冲突的依赖关系并修复它们。

今天早上我因同样的错误而苦苦挣扎,并且对 multiDexEnabled 的要求没有意义。这仅适用于方法数超过 64k 的大型项目。我在 SO 的某个地方找到了这个解决方案,但再也找不到了。所以重新发布答案。

【讨论】:

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