多个dex文件定义Lcom/谷歌/android/gms/内部/zzau。

时间:2021-04-24 18:58:34

I get the error com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzau; when i run my app The gradle files are

我得到错误。android.dex.dexexception:多个dex文件定义Lcom/谷歌/android/gms/内部/zzau;当我运行我的应用程序时,gradle文件是。

app.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

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'
}

How do i fix this? i guess the error occurs because i use google play services in both the module and the app. but the versions are different. is that causing an issue?

我怎么解决这个问题?我想错误发生是因为我在模块和应用程序中都使用谷歌游戏服务,但是版本不同。这会导致一个问题吗?

7 个解决方案

#1


27  

I had similar problem and your question helped me solve mine and probably will help you solve yours. Problem is that you have defined:

我也有类似的问题,你的问题帮助我解决了我的问题,也许能帮你解决问题。问题是你已经定义了:

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

and

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

Since google services 7.5.0, if you're using single modules from play services you can't use whole play services as dependency simultaneously. Solution is to select only those services that you need instead of whole package e.g.:

由于谷歌服务7.5.0,如果您使用的是游戏服务的单个模块,您不能同时使用整个游戏服务作为依赖项。解决方案是只选择您需要的服务,而不是整个包。

instead of

而不是

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

use

使用

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.+'
...
}

Also I'm not sure but probably it would be good idea to use the same version of google services in both gradle configs.

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

#2


15  

I had a similar problem after building using phonegap/cordova: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzsk;

使用phonegap/cordova: com.android. dex.dex.dexexception:多个dex文件定义Lcom/谷歌/android/gms/内部/zzsk;

I fixed it by editing build.gradle(module Android), as I had 2 libraries that should have the exact same version with different version numbers (8.4.0 and 9.2.1 in my case)

我通过编辑构建来修复它。gradle(模块Android),我有两个库,应该有完全相同的版本,版本号不同(在我的例子中是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
....
}

#3


3  

Had the same issue while integrating firebase. For my case, it was caused by version mismatch.

在集成firebase时遇到了同样的问题。对于我来说,它是由版本不匹配引起的。

on the app gradle, i had:

在app 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'
}

the firebase dependancy was added through the integrated firebase plugin in Android studio. When i matched the versions, it worked.

在Android studio的集成firebase插件中添加了firebase依赖性。当我匹配这些版本时,它起作用了。

#4


2  

I had this issue recently, the reason was the version difference:

我最近有这个问题,原因是版本差异:

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

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

so make sure you have the same version.

所以一定要有相同的版本。

#5


2  

I encountered the same issue after manually adding Firebase to my app.
For me the solution was changing:

我在app中手动添加Firebase后遇到了同样的问题。

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

to:

:

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

in the root-level build.gradle file.

在root。gradle文件。

#6


2  

If this is happening with react-native-device-info, you can only change from:

如果这种情况发生在反应生成设备信息中,那么您只能从以下方式进行更改:

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

to

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

As described here: https://github.com/rebeccahughes/react-native-device-info/blob/81b0c20fab8a10ccf0341dbd6710d7a5915b06a6/README.md#troubleshooting

这里所描述的那样:https://github.com/rebeccahughes/react-native-device-info/blob/81b0c20fab8a10ccf0341dbd6710d7a5915b06a6/README.md #故障排除

#7


1  

I had the same problem but mine was cause by firebase-ui newest version 2.0.0. So I downgraded to 1.2.0 and added the following line to Project level build.gradle file:

我有同样的问题,但我的原因是firebase-ui最新版本2.0.0。因此,我将其降级为1.2.0,并将以下代码添加到项目级别构建中。gradle文件:

allprojects {
    repositories {
        jcenter()

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

#1


27  

I had similar problem and your question helped me solve mine and probably will help you solve yours. Problem is that you have defined:

我也有类似的问题,你的问题帮助我解决了我的问题,也许能帮你解决问题。问题是你已经定义了:

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

and

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

Since google services 7.5.0, if you're using single modules from play services you can't use whole play services as dependency simultaneously. Solution is to select only those services that you need instead of whole package e.g.:

由于谷歌服务7.5.0,如果您使用的是游戏服务的单个模块,您不能同时使用整个游戏服务作为依赖项。解决方案是只选择您需要的服务,而不是整个包。

instead of

而不是

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

use

使用

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.+'
...
}

Also I'm not sure but probably it would be good idea to use the same version of google services in both gradle configs.

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

#2


15  

I had a similar problem after building using phonegap/cordova: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzsk;

使用phonegap/cordova: com.android. dex.dex.dexexception:多个dex文件定义Lcom/谷歌/android/gms/内部/zzsk;

I fixed it by editing build.gradle(module Android), as I had 2 libraries that should have the exact same version with different version numbers (8.4.0 and 9.2.1 in my case)

我通过编辑构建来修复它。gradle(模块Android),我有两个库,应该有完全相同的版本,版本号不同(在我的例子中是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
....
}

#3


3  

Had the same issue while integrating firebase. For my case, it was caused by version mismatch.

在集成firebase时遇到了同样的问题。对于我来说,它是由版本不匹配引起的。

on the app gradle, i had:

在app 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'
}

the firebase dependancy was added through the integrated firebase plugin in Android studio. When i matched the versions, it worked.

在Android studio的集成firebase插件中添加了firebase依赖性。当我匹配这些版本时,它起作用了。

#4


2  

I had this issue recently, the reason was the version difference:

我最近有这个问题,原因是版本差异:

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

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

so make sure you have the same version.

所以一定要有相同的版本。

#5


2  

I encountered the same issue after manually adding Firebase to my app.
For me the solution was changing:

我在app中手动添加Firebase后遇到了同样的问题。

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

to:

:

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

in the root-level build.gradle file.

在root。gradle文件。

#6


2  

If this is happening with react-native-device-info, you can only change from:

如果这种情况发生在反应生成设备信息中,那么您只能从以下方式进行更改:

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

to

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

As described here: https://github.com/rebeccahughes/react-native-device-info/blob/81b0c20fab8a10ccf0341dbd6710d7a5915b06a6/README.md#troubleshooting

这里所描述的那样:https://github.com/rebeccahughes/react-native-device-info/blob/81b0c20fab8a10ccf0341dbd6710d7a5915b06a6/README.md #故障排除

#7


1  

I had the same problem but mine was cause by firebase-ui newest version 2.0.0. So I downgraded to 1.2.0 and added the following line to Project level build.gradle file:

我有同样的问题,但我的原因是firebase-ui最新版本2.0.0。因此,我将其降级为1.2.0,并将以下代码添加到项目级别构建中。gradle文件:

allprojects {
    repositories {
        jcenter()

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