【问题标题】:Gradle: Error: more than one library with package name 'com.google.android.gms'Gradle:错误:多个库的包名称为“com.google.android.gms”
【发布时间】:2014-06-23 01:50:55
【问题描述】:

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

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

我的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')
}

【问题讨论】:

    标签: android gradle android-gradle-plugin build.gradle


    【解决方案1】:

    我长期以来一直对这个问题感到困惑。尽管相同的错误日志,但我的问题与问题略有不同。我希望我的 sublib 的构建类型与我的应用程序的构建类型相同。因此,正如文档告诉我的那样,我为 sublib 分配了构建类型。 [Gradle 插件使用指南][1]

    这是我得到的错误。

    处理flavorCustomResource

    错误:多个库包含 com.xxx.libCommon

    这是我的结构。 lib1 和 lib2 相互独立。

    应用程序

    -> lib1 -> libCommon

    -> lib2 -> libCommon

    我只有在构建自定义 buildtype 时才收到错误消息。但是,发布版本没问题。

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

    应用程序:

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

    lib1:

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

    lib2

    dependencies {
        compile project(':libCommon')
    }
    

    解决方法:将lib2配置为lib1。问题会解决的。

    lib2:

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

    原因

    问题在于图书馆出版

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

    我希望我的帖子能帮助遇到同样问题的人或给他/她一些提示。

    【讨论】:

    • 很好的解释。它帮助我找到了类似的问题。对于我的内部库依赖项之一,我依赖于我的自定义构建类型的发布版本。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      今天我遇到了同样的问题。我需要使用谷歌分析,所以我按照教程导入谷歌分析库:

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

      然后编译项目,gradle告诉我Error: more than one library with package name 'com.google.android.gms'

      我可以肯定的是,我只通过google analytics lib 直接导入com.google.android.gms 一次。

      所以我导航到 Android Studio 中的 Project 选项卡以查看该项目所依赖的库是什么,然后我发现 play-services-6.5.87 显示在 External Libraries 中,如下图所示:

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

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

      $ ./gradlew -q app:dependencies
      

      结果告诉我com.facebook.android:audience-network-sdk:4.6.0 依赖它。

      那么我们如何解决这个问题,有两种方法:

      1. 如果您不需要这个audience-network-sdk,只需将其删除。我的项目实际上不需要它。
      2. 如果您还需要audience-network-sdkgoogle-analytics,请使用exclude group 语法,如以下sn-p 代码。

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

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

      【讨论】:

      • 完美解决方案。允许我确定重复依赖项的来源。
      • 您也可以使用exclude module: 'play-services' 代替exclude group 命令。
      • 为了方便查找/搜索,请在 windows 中使用以下命令gradlew -q app:dependencies > c:\dependencies.log
      【解决方案4】:

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

      【讨论】:

      • 嗨。感谢您的回答,但没有帮助(
      • 我找到了解决方案!我只是在我的build.gradle 在您的帖子之后,我了解到问题出在 build.gradle 文件中。非常感谢! +1
      【解决方案5】:

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

      1. 离子平台 rm android

      2. 离子平台添加安卓

      3. 离子构建安卓

      【讨论】:

      • 完全无关
      • 你用原生脚本解决了我同样的问题。
      【解决方案6】:

      就我而言,问题是因为我包括:

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

      可穿戴游戏服务和常规服务。 我注释掉了可穿戴部分,它可以工作。
      不确定我是否需要它,但项目向导默认包含它

      【讨论】:

      • 嗯,如果我注释掉 google-maps lib,编译器会说找不到 LocationClient。奇怪......我认为这是由模块化依赖引起的。
      • 谢谢 - 这节省了一些时间!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多