多个 dex 文件定义 Lcom/google/android/gms/internal/zzau

Multiple dex files define Lcom/google/android/gms/internal/zzau

我在 运行 我的应用程序时收到错误 com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzau; gradle 个文件是

app.gradle

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.google.android.gms:play-services:7.0.+'
compile 'com.android.support:mediarouter-v7:21.0.3'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.github.ksoichiro:android-observablescrollview:1.4.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.edmodo:rangebar:1.0.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile project(':library_viewpager')
compile project(':androidHorizontalListView')
compile project(':CastCompanionLibrary')
compile project(':mobihelp_sdk_android_v1.4')
compile fileTree(include: 'Parse-*.jar', dir: 'libs')
compile files('libs/Parse-1.9.2.jar')
compile files('libs/GoogleConversionTrackingSdk-2.2.2.jar')
}

CastCompanionLibrary

dependencies {
compile 'com.android.support:appcompat-v7:22.+'
compile 'com.android.support:mediarouter-v7:22.+'
compile 'com.google.android.gms:play-services-cast:7.5.0'
}

我该如何解决这个问题?我想错误发生是因为我在模块和应用程序中都使用了 google 播放服务。但版本不同。这会导致问题吗?

我遇到了类似的问题,你的问题帮助我解决了我的问题,可能也会帮助你解决你的问题。问题是你定义了:

dependencies {
...
  compile 'com.google.android.gms:play-services-cast:7.5.0'
}

dependencies {
...
  compile 'com.google.android.gms:play-services:7.0.+'
...
}

自 google 服务 7.5.0 起,如果您使用播放服务中的单个模块,则不能同时使用整个播放服务作为依赖项。解决方案是 select 只提供您需要的那些服务,而不是整个服务包,例如:

而不是

dependencies {
...
  compile 'com.google.android.gms:play-services:7.0.+'
...
}

使用

dependencies {
...
  compile 'com.google.android.gms:play-services-maps:7.0.+'
  compile 'com.google.android.gms:play-services-location:7.0.+'
  compile 'com.google.android.gms:play-services-gcm:7.0.+'
...
}

我也不确定,但在两个 gradle 配置中使用相同版本的 google 服务可能是个好主意。

使用 phonegap/cordova 构建后我遇到了类似的问题: com.android.dex.DexException:多个dex文件定义Lcom/google/android/gms/internal/zzsk;

我通过编辑 build.gradle(模块 Android)修复了它,因为我有 2 个库应该具有完全相同的版本但版本号不同(我的 8.4.0 和 9.2.1例)

dependencies{
....
//make sure are both same version (8.4.0 or 9.2.1 in my case)
compile 'com.google.android.gms:play-services-gcm:9.2.1'
// this is the one I changed:  compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-location:9.2.1' // it was 8.4.0
....
}

集成 Firebase 时遇到同样的问题。我的情况是版本不匹配导致的。

在应用 gradle 上,我有:

ext {
    PLAY_SERVICES_VERSION = '10.2.0'
}
dependencies {
    compile "com.google.android.gms:play-services-maps:$PLAY_SERVICES_VERSION"
    compile "com.google.android.gms:play-services-location:$PLAY_SERVICES_VERSION"
    compile "com.google.android.gms:play-services-places:$PLAY_SERVICES_VERSION"
    compile 'com.google.firebase:firebase-database:10.0.1'
}

firebase 依赖项是通过 Android studio 中的集成 firebase 插件添加的。当我匹配版本时,它起作用了。

我遇到了同样的问题,但我的问题是由 firebase-ui 最新版本 2.0.0 引起的。所以我降级到 1.2.0 并将以下行添加到项目级别 build.gradle 文件:

allprojects {
    repositories {
        jcenter()

        // Add the following code
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

最近遇到这个问题,原因是版本不同:

'com.google.firebase:firebase-ads:9.0.6'

'com.google.firebase:firebase-crash:11.0.2'

所以请确保您拥有相同的版本。

我在将 Firebase 手动添加到我的应用程序后遇到了同样的问题。
对我来说,解决方案正在改变:

classpath 'com.google.gms:google-services:3.2.0'

至:

classpath 'com.google.gms:google-services:3.0.0'

在 root-level build.gradle 文件中。

如果 react-native-device-info 出现这种情况,您只能更改为:

compile(project(':react-native-device-info'))

compile(project(':react-native-device-info')) {
  exclude group: 'com.google.android.gms'
}

如此处所述: https://github.com/rebeccahughes/react-native-device-info/blob/81b0c20fab8a10ccf0341dbd6710d7a5915b06a6/README.md#troubleshooting

我的项目是一个 cordova ionic1 项目,我花了整整一个晚上和一个早上来解决这个问题,这就是我所做的,因为我有 firebase 依赖项和 google 服务: 转到此文件: platforms\android\cordova-plugin-firebase\cordova-plugin-firebase\app-build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        // classpath 'com.google.gms:google-services:3.0.0'
        // i changed the above line from 3.0.0 to 3.1.1
        classpath 'com.google.gms:google-services:3.1.1'
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile 'me.leolin:ShortcutBadger:1.1.4@aar'
    //compile 'com.google.firebase:firebase-crash:+'
    // i changed the above line from + to 11.0.2
    compile 'com.google.firebase:firebase-crash:11.0.2'
}

然后转到此文件: platforms\android\project.属性 本来我有这个

target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-firebase/app-build.gradle
cordova.system.library.1=com.google.gms:google-services:+
cordova.system.library.2=com.google.firebase:firebase-core:+
cordova.system.library.3=com.google.firebase:firebase-messaging:+
cordova.system.library.4=com.google.firebase:firebase-crash:+
cordova.system.library.5=com.google.firebase:firebase-config:+
cordova.system.library.6=com.android.support:support-v4:24.1.1+
cordova.system.library.7=com.google.android.gms:play-services-auth:11.+
cordova.system.library.8=com.google.android.gms:play-services-identity:11.+

然后我注释掉了 google 服务,因为我们需要特定的依赖项,我还将 firebase 和 gms 的版本设置为相同的版本号 11.0.2 所以在我的文件看起来像这样之后

target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-firebase/app-build.gradle
# cordova.system.library.1=com.google.gms:google-services:+
cordova.system.library.2=com.google.firebase:firebase-core:11.0.2
cordova.system.library.3=com.google.firebase:firebase-messaging:11.0.2
cordova.system.library.4=com.google.firebase:firebase-crash:11.0.2
cordova.system.library.5=com.google.firebase:firebase-config:11.0.2
cordova.system.library.6=com.android.support:support-v4:24.1.1+
cordova.system.library.7=com.google.android.gms:play-services-auth:11.0.2
cordova.system.library.8=com.google.android.gms:play-services-identity:11.0.2

我遇到了这个问题,none 的解决方案有效。对我有用的是添加这个插件

 cordova plugin add cordova-android-play-services-gradle-release --save

然后在 /platforms/android/cordova-plugin-fcm/ 和 /platforms/android/cordova-plugin-open/ 中替换

apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

与:

ext.postBuildExtras = {
  apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

Firebase Android SDKs now have independent version numbers, allowing for more frequent, flexible updates.

将所有 Firebase 依赖项更新到最新版本(截至 2018 年 5 月 2 日):

 Firebase Core          com.google.firebase:firebase-core:15.0.2
    Ads                 com.google.firebase:firebase-ads:15.0.0
  Analytics             com.google.firebase:firebase-analytics:15.0.2
 App Indexing           com.google.firebase:firebase-appindexing:15.0.0
 Authentication         com.google.firebase:firebase-auth:15.1.0
Cloud Firestore         com.google.firebase:firebase-firestore:16.0.0
Cloud Functions         com.google.firebase:firebase-functions:15.0.0
Cloud Messaging         com.google.firebase:firebase-messaging:15.0.2
Cloud Storage           com.google.firebase:firebase-storage:15.0.2
Crash Reporting         com.google.firebase:firebase-crash:15.0.2
Crashlytics             com.crashlytics.sdk.android:crashlytics:2.9.1
Invites                 com.google.firebase:firebase-invites:15.0.2
Performance Monitoring  com.google.firebase:firebase-perf:15.1.0
Realtime Database       com.google.firebase:firebase-database:15.0.0
Remote Config           com.google.firebase:firebase-config:15.0.2

发行说明:https://firebase.google.com/support/release-notes/android

如果有人遇到与我相同的问题,我删除了 firebase-core 依赖项,它非常有效。

dependencies{
    implementation 'com.google.firebase:firebase-core:15.0.0'
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
    implementation 'com.google.firebase:firebase-crash:15.0.0'
    implementation 'com.google.firebase:firebase-messaging:15.0.0'
}

dependencies{
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
    implementation 'com.google.firebase:firebase-crash:15.0.0'
    implementation 'com.google.firebase:firebase-messaging:15.0.0'
}

如果其他人在 Ionic 删除并重新添加对我有用的平台时遇到此问题:

> ionic cordova rm platform android
> ionic cordova add platform android

对于任何想知道如何为 Apache Cordova 插件 修复此问题的人,我通过确保所有 plugin.xml 文件包含 相同的主要和次要版本,但最新修订,如下所示:

<framework src="com.google.firebase:firebase-auth:15.0.+" />
<framework src="com.google.firebase:firebase-messaging:15.0.+" />

当使用上面的 15.0.0 时,由于某种原因出现了 com.android.dex.DexException 错误。通过使用 + 作为修订号(即最新版本),一切都与 cordova 7.1.0 和 cordova-android 6.3.0.

完美配合

记得从插件编辑 plugin.xml 删除并重新添加 android 平台 ,否则您的更改根本不会应用!

另外:确保只有一个 gradle 文件应用此,以防万一:

dependencies {
    classpath 'com.android.tools.build:gradle:+'
    classpath 'com.google.gms:google-services:3.0.0'
}

我也遇到了这个问题,我尝试了很多方法来解决这个问题。对我有用的是从我的 gradle.

中删除以下行
compile 'com.google.firebase:firebase-core:16.0.3'

起初我有firebase-corefirebase-ml-vision(我只需要firebase-ml-vision),如下所示。

compile 'com.google.firebase:firebase-ml-vision:17.0.0'
compile 'com.google.firebase:firebase-core:16.0.3'

删除该行后,我收到以下警告,

Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.

但是,根据官方文档,核心依赖项可能不存在 (https://firebase.google.com/docs/ml-kit/android/detect-faces),因此可以忽略。