【问题标题】:ERROR Multiple dex files define Lcom/google/android/gms/location/places/zza;ERROR 多个 dex 文件定义 Lcom/google/android/gms/location/places/zza;
【发布时间】:2018-06-23 13:03:04
【问题描述】:

我从 2 天开始就面临这个问题,仍然没有找到任何解决方案。 我尝试更改库的版本、清理和构建项目以及使缓存无效等。

下面是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.root.ambulancetracking"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    //noinspection GradleCompatible
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:27.1.1'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:support-v4:27.1.1'
    compile 'com.android.support:design:27.1.1'
    compile 'com.android.support:recyclerview-v7:27.1.1'
    compile 'com.android.support:cardview-v7:27.1.1'
    compile 'com.google.firebase:firebase-messaging:17.0.0'
    compile 'com.google.firebase:firebase-core:16.0.0'
    compile 'com.google.android.gms:play-services-location:15.0.1'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.github.ar-android:DrawRouteMaps:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}

下面是build.gradle(项目):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我在消息窗口中得到的内容。

Information:Gradle tasks [:app:assembleDebug]
Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/location/places/zza;
Information:BUILD FAILED in 1m 22s
Information:4 errors
Information:0 warnings
Information:See complete output in console

我尽力了

请提供任何帮助。
非常感谢您在此问题上的时间和帮助。

【问题讨论】:

  • 你能添加完整的错误跟踪吗
  • 我用错误消息更新了我的问题。
  • 你需要启用multidex。
  • 已经做到了。

标签: java android android-gradle-plugin android-multidex


【解决方案1】:

请添加此库以解决此问题

implementation 'com.android.support:multidex:1.0.3'

另外,在您的应用程序类中启用 multidex

    @Override
    public void onCreate() {
        super.onCreate();
        MultiDex.install(this);
  }

【讨论】:

    【解决方案2】:

    你的版本有冲突

    compile 'com.google.firebase:firebase-messaging:17.0.0'
    compile 'com.google.firebase:firebase-core:16.0.0'
    compile 'com.google.android.gms:play-services-location:15.0.1'
    

    隐蔽到这一行:

    compile 'com.google.firebase:firebase-messaging:17.0.0'
    compile 'com.google.firebase:firebase-core:17.0.0'
    compile 'com.google.android.gms:play-services-location:17.0.0'
    

    【讨论】:

      【解决方案3】:

      如果您使用 3.3.0 以下的 google play service 插件,则需要使用相同版本的 Firebase 和 Google Play Service。

      如果您想使用多个版本的 Firebase 和 Google Play Service(从版本 15 开始),您需要use google play service plugin 3.3.0。因此,将您的项目build.gradle 更改为:

      // Top-level build file where you can add configuration options common to all sub-projects/modules.
      
      buildscript {
      
          repositories {
              google()
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.0.1'
              classpath 'com.google.gms:google-services:3.3.0'
      
              // NOTE: Do not place your application dependencies here; they belong
              // in the individual module build.gradle files
          }
      }
      
      ...
      

      最后,不要忘记添加以下行:

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

      到您的应用 build.gradle的底部

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-01
        • 2018-01-15
        • 2017-08-14
        • 1970-01-01
        • 2018-10-15
        • 1970-01-01
        相关资源
        最近更新 更多