Gradle:错误:包含名称为“com.google.android.gms”的多个库

时间:2022-10-12 00:26:30

What does this error message mean? I don't have duplicated packages in my project

这个错误信息是什么意思?我的项目中没有重复的包

Error:Execution failed for task ':SimpleReader:processDebugResources'.
Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with android.enforceUniquePackageName=false However, this is temporary and will be enforced in 1.0

错误:任务':SimpleReader:processDebugResources'的执行失败。错误:包含名称为“com.google.android.gms”的多个库您可以使用android.enforceUniquePackageName = false临时禁用此错误但是,这是临时的,将在1.0中强制执行

My build.gradle looks like this:

我的build.gradle看起来像这样:

buildscript {

    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.1'
    }
}
apply plugin: 'android'
android {
    buildToolsVersion '19.0.3'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 17

    }
    compileSdkVersion 17
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    buildTypes {
    }
}
dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.google.android.gms:play-services:4.2.42'
    compile files('libs/gson-2.2.4.jar')
    compile files('libs/httpmime-4.1.jar')
    compile files('libs/httpclient-4.1.1.jar')
    compile files('libs/jsoup-1.7.3.jar')
    compile project(':libraries:actionbarsherlock')
    compile project(':libraries:sherlocknavigationdrawer')
    compile project(':libraries:googleplayservices')
    compile project(':libraries:androidslidinguppanel')
    compile files('libs/protocol-1.0.4.jar')
    compile files('libs/sentry-0.1.4.jar')
    compile files('libs/commons-lang-2.3.jar')
}

6 个解决方案

#1


33  

In my case, the problem was because I was including:

在我的情况下,问题是因为我包括:

compile 'com.google.android.gms:play-services-wearable:+'
compile 'com.google.android.gms:play-services:4.4.52'

both the wearable play services, and the regular. I commented out the wearable part, and it works.
Not sure if I'll need it, but it was included by default by the project wizard

可穿戴式游戏服务和常规服务。我评论了可穿戴部分,它起作用了。不确定我是否需要它,但项目向导默认包含它

#2


15  

today I met the same problem. I need to use Google Analytics, so I import google analytics lib following the tutorial:

今天我遇到了同样的问题。我需要使用Google Analytics,因此我按照教程导入google analytics lib:

compile 'com.google.android.gms:play-services-analytics:9.0.0'

then compile the project, gradle tell me Error: more than one library with package name 'com.google.android.gms'

然后编译项目,gradle告诉我错误:包含名称为'com.google.android.gms'的多个库

I can definitely sure that I only directly import com.google.android.gms one time by google analytics lib.

我绝对可以肯定我只能通过谷歌分析库直接导入com.google.android.gms一次。

so I navigate to Project tab in Android Studio to see what are the libs this project depend on, then I found play-services-6.5.87 display in External Libraries, like following screenshot:

所以我导航到Android Studio中的Project选项卡,看看这个项目所依赖的库是什么,然后我发现外部库中的play-services-6.5.87显示,如下面的截图:

Gradle:错误:包含名称为“com.google.android.gms”的多个库

so now I know there is another lib depend on play-services-6.5.87, but I don't which lib it is.

所以现在我知道有另一个lib依赖于play-services-6.5.87,但我不是它的lib。

then I use a gradle command in console to see the project dependencies:

然后我在控制台中使用gradle命令来查看项目依赖项:

$ ./gradlew -q app:dependencies

Gradle:错误:包含名称为“com.google.android.gms”的多个库

the result tells me that com.facebook.android:audience-network-sdk:4.6.0 depend on it.

结果告诉我com.facebook.android:audience-network-sdk:4.6.0取决于它。

so how we fix this problem, two way:

所以我们如何解决这个问题,两种方式:

  1. if you don't need this audience-network-sdk, just remove it. my project in fact doesn't need it.
  2. 如果您不需要此audience-network-sdk,请将其删除。事实上,我的项目不需要它。
  3. if you also need audience-network-sdk and google-analytics, use exclude group grammar, like following snippet code.

    如果您还需要audience-network-sdk和google-analytics,请使用排除组语法,例如以下代码段。

    //facebook SDK
    compile ('com.facebook.android:audience-network-sdk:4.6.0') 
            {exclude group: 'com.google.android.gms'}
    
    // google analytics
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
    

in your case, the audience-network-sdk can be any other lib that depends on same lib with other libs. here is just a thinking of how to resolve similar problems.

在您的情况下,audience-network-sdk可以是依赖于与其他lib相同的lib的任何其他lib。这里只是思考如何解决类似的问题。

#3


7  

Try removing compile project(':libraries:googleplayservices') or compile 'com.google.android.gms:play-services:4.2.42'. I am pretty sure they are the same library.

尝试删除编译项目(':libraries:googleplayservices')或编译'com.google.android.gms:play-services:4.2.42'。我很确定它们是同一个库。

#4


1  

I faced similar issue, i got it resolved by following steps:

我遇到了类似的问题,我通过以下步骤解决了问题:

  1. ionic platform rm android

    离子平台rm android

  2. ionic platform add android

    离子平台添加android

  3. ionic build android

    离子构建android

#5


1  

this is a problem with versions. if you have multiple dependencies of same package path ensure the versions are the same

这是版本的问题。如果您有相同包路径的多个依赖项,请确保版本相同

compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'

#6


1  

I had confused with this problem for a long time.My issue is little different with the question though same error log. I want my sublib's buildtype same with my application's buildtype. So I assigned the buildtype for sublib as the document tells me. [Gradle Plugin User Guide][1]

我很长一段时间都对这个问题感到困惑。虽然同样的错误日志,我的问题与问题没有什么不同。我希望我的sublib的buildtype与我的应用程序的buildtype相同。所以我为文档告诉我分配了sublib的构建类型。 [Gradle插件用户指南] [1]

This the error I got.

这是我得到的错误。

processing flavorCustomResource

处理flavorCustomResource

Error: more than one library with com.xxx.libCommon

错误:使用com.xxx.libCommon的多个库

This is my structure. lib1 and lib2 are independent of each other.

这是我的结构。 lib1和lib2彼此独立。

app

应用

-> lib1 -> libCommon

- > lib1 - > libCommon

-> lib2 -> libCommon

- > lib2 - > libCommon

I got the error only when I build my custom buildtype.However, The release version was Ok.

我只有在构建自定义构建类型时才会出错。但是,发布版本是好的。

More details. some parts of my build.gradle

更多细节。我的build.gradle的一些部分

app:

应用:

android {
    buildTypes {
        release{}
        custom{}
    }
}
configurations {
    flavorReleaseCompile
    flavorCustomCompile
}
dependencies{
    compile project(':lib1')
    flavorReleaseCompile project(path: ':lib2', configuration: ':release')
    flavorCustomCompile project(path: ':lib2', configuration: ':custom')
}

lib1:

LIB1:

android {
    publishNonDefault true
    buildTypes {
        release{}
        custom{}
    }
}

dependencies{
    releaseCompile project(path: ':libCommon', configuration: ':release')
    customCompile project(path: ':libCommon', configuration: ':custom')
}

lib2

LIB2

dependencies {
    compile project(':libCommon')
}

Solution: configure the lib2 as lib1. the problem will be solved.

解决方案:将lib2配置为lib1。问题将得到解决。

lib2:

LIB2:

android {
    publishNonDefault true
    buildTypes {
        release{}
        custom{}
    }
}

dependencies{
    releaseCompile project(path: ':libCommon', configuration: ':release')
    customCompile project(path: ':libCommon', configuration: ':custom')
}

Reason

原因

The problem is something about Library Publication

关于图书馆出版的问题

The default publish is release. if lib2 is not configured, it will use the default publish libCommon(release version) which is different from lib1 -> libCommon(custom version) assigned by lib1's build.gradle.This comes the error.

默认发布是发布。如果没有配置lib2,它将使用默认发布libCommon(发行版本),它与lib1 - > libCommon(自定义版本)不同,由lib1的build.gradle分配。这就出现了错误。

I wish my post will help someone struggle with the same issue or give some hint to him/her.

我希望我的帖子能帮助某些人解决同样的问题,或者给他/她一些暗示。

#1


33  

In my case, the problem was because I was including:

在我的情况下,问题是因为我包括:

compile 'com.google.android.gms:play-services-wearable:+'
compile 'com.google.android.gms:play-services:4.4.52'

both the wearable play services, and the regular. I commented out the wearable part, and it works.
Not sure if I'll need it, but it was included by default by the project wizard

可穿戴式游戏服务和常规服务。我评论了可穿戴部分,它起作用了。不确定我是否需要它,但项目向导默认包含它

#2


15  

today I met the same problem. I need to use Google Analytics, so I import google analytics lib following the tutorial:

今天我遇到了同样的问题。我需要使用Google Analytics,因此我按照教程导入google analytics lib:

compile 'com.google.android.gms:play-services-analytics:9.0.0'

then compile the project, gradle tell me Error: more than one library with package name 'com.google.android.gms'

然后编译项目,gradle告诉我错误:包含名称为'com.google.android.gms'的多个库

I can definitely sure that I only directly import com.google.android.gms one time by google analytics lib.

我绝对可以肯定我只能通过谷歌分析库直接导入com.google.android.gms一次。

so I navigate to Project tab in Android Studio to see what are the libs this project depend on, then I found play-services-6.5.87 display in External Libraries, like following screenshot:

所以我导航到Android Studio中的Project选项卡,看看这个项目所依赖的库是什么,然后我发现外部库中的play-services-6.5.87显示,如下面的截图:

Gradle:错误:包含名称为“com.google.android.gms”的多个库

so now I know there is another lib depend on play-services-6.5.87, but I don't which lib it is.

所以现在我知道有另一个lib依赖于play-services-6.5.87,但我不是它的lib。

then I use a gradle command in console to see the project dependencies:

然后我在控制台中使用gradle命令来查看项目依赖项:

$ ./gradlew -q app:dependencies

Gradle:错误:包含名称为“com.google.android.gms”的多个库

the result tells me that com.facebook.android:audience-network-sdk:4.6.0 depend on it.

结果告诉我com.facebook.android:audience-network-sdk:4.6.0取决于它。

so how we fix this problem, two way:

所以我们如何解决这个问题,两种方式:

  1. if you don't need this audience-network-sdk, just remove it. my project in fact doesn't need it.
  2. 如果您不需要此audience-network-sdk,请将其删除。事实上,我的项目不需要它。
  3. if you also need audience-network-sdk and google-analytics, use exclude group grammar, like following snippet code.

    如果您还需要audience-network-sdk和google-analytics,请使用排除组语法,例如以下代码段。

    //facebook SDK
    compile ('com.facebook.android:audience-network-sdk:4.6.0') 
            {exclude group: 'com.google.android.gms'}
    
    // google analytics
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
    

in your case, the audience-network-sdk can be any other lib that depends on same lib with other libs. here is just a thinking of how to resolve similar problems.

在您的情况下,audience-network-sdk可以是依赖于与其他lib相同的lib的任何其他lib。这里只是思考如何解决类似的问题。

#3


7  

Try removing compile project(':libraries:googleplayservices') or compile 'com.google.android.gms:play-services:4.2.42'. I am pretty sure they are the same library.

尝试删除编译项目(':libraries:googleplayservices')或编译'com.google.android.gms:play-services:4.2.42'。我很确定它们是同一个库。

#4


1  

I faced similar issue, i got it resolved by following steps:

我遇到了类似的问题,我通过以下步骤解决了问题:

  1. ionic platform rm android

    离子平台rm android

  2. ionic platform add android

    离子平台添加android

  3. ionic build android

    离子构建android

#5


1  

this is a problem with versions. if you have multiple dependencies of same package path ensure the versions are the same

这是版本的问题。如果您有相同包路径的多个依赖项,请确保版本相同

compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'

#6


1  

I had confused with this problem for a long time.My issue is little different with the question though same error log. I want my sublib's buildtype same with my application's buildtype. So I assigned the buildtype for sublib as the document tells me. [Gradle Plugin User Guide][1]

我很长一段时间都对这个问题感到困惑。虽然同样的错误日志,我的问题与问题没有什么不同。我希望我的sublib的buildtype与我的应用程序的buildtype相同。所以我为文档告诉我分配了sublib的构建类型。 [Gradle插件用户指南] [1]

This the error I got.

这是我得到的错误。

processing flavorCustomResource

处理flavorCustomResource

Error: more than one library with com.xxx.libCommon

错误:使用com.xxx.libCommon的多个库

This is my structure. lib1 and lib2 are independent of each other.

这是我的结构。 lib1和lib2彼此独立。

app

应用

-> lib1 -> libCommon

- > lib1 - > libCommon

-> lib2 -> libCommon

- > lib2 - > libCommon

I got the error only when I build my custom buildtype.However, The release version was Ok.

我只有在构建自定义构建类型时才会出错。但是,发布版本是好的。

More details. some parts of my build.gradle

更多细节。我的build.gradle的一些部分

app:

应用:

android {
    buildTypes {
        release{}
        custom{}
    }
}
configurations {
    flavorReleaseCompile
    flavorCustomCompile
}
dependencies{
    compile project(':lib1')
    flavorReleaseCompile project(path: ':lib2', configuration: ':release')
    flavorCustomCompile project(path: ':lib2', configuration: ':custom')
}

lib1:

LIB1:

android {
    publishNonDefault true
    buildTypes {
        release{}
        custom{}
    }
}

dependencies{
    releaseCompile project(path: ':libCommon', configuration: ':release')
    customCompile project(path: ':libCommon', configuration: ':custom')
}

lib2

LIB2

dependencies {
    compile project(':libCommon')
}

Solution: configure the lib2 as lib1. the problem will be solved.

解决方案:将lib2配置为lib1。问题将得到解决。

lib2:

LIB2:

android {
    publishNonDefault true
    buildTypes {
        release{}
        custom{}
    }
}

dependencies{
    releaseCompile project(path: ':libCommon', configuration: ':release')
    customCompile project(path: ':libCommon', configuration: ':custom')
}

Reason

原因

The problem is something about Library Publication

关于图书馆出版的问题

The default publish is release. if lib2 is not configured, it will use the default publish libCommon(release version) which is different from lib1 -> libCommon(custom version) assigned by lib1's build.gradle.This comes the error.

默认发布是发布。如果没有配置lib2,它将使用默认发布libCommon(发行版本),它与lib1 - > libCommon(自定义版本)不同,由lib1的build.gradle分配。这就出现了错误。

I wish my post will help someone struggle with the same issue or give some hint to him/her.

我希望我的帖子能帮助某些人解决同样的问题,或者给他/她一些暗示。