2014-05-06 42 views
31

此错误消息的含义是什么?我没有在我的项目复制包Gradle:错误:包名称不止一个库'com.google.android.gms'

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

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

回答

32

对我来说,这个问题是因为我,包括:

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

都穿戴式播放服务,并定期。 我评论了可穿戴部分,它的工作原理。
不知道我是否会需要它,但它默认包含由

+0

嗯,如果我注释掉谷歌-maps lib,编译器说找不到LocationClient。奇怪...我认为这是由模块化依赖引起的。 –

+0

谢谢 - 这节省了一些时间! – CapeCoder

7

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

+0

嗨。感谢您的回答,但没有帮助( –

+2

我找到了解决方案!我只是将gms play-service compile编译为com.google.android.gms:play-services:4.2.42' 以编译'com。 google.android.gms:play-services:4.3.23'在我的build.gradle 之后你的帖子我明白这个问题是在build.gradle文件中。非常感谢!+1 –

-1

我面临着类似的问题,项目向导中,我得到了它决心在以下步骤:

  1. 离子平台的Android RM

  2. 离子平台添加的Android

  3. 离子构建Android

+0

嗨。我不使用Ionic Framework –

+0

完全不相关 –

+0

您已解决我用原生脚本建立了这个问题 – realtebo

14

今天我遇到了同样的问题。我需要使用谷歌Analytics(分析),所以我导入谷歌分析的lib下面的教程:

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

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

我绝对可以肯定,我只直接被导入com.google.android.gms一次google analytics lib。

所以我浏览到Project标签Android Studio中看到什么是这个项目依赖于库,后来我发现play-services-6.5.87显示在External Libraries,如下面的截图:

see External Libraries

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

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

$ ./gradlew -q app:dependencies 

gradle dependencies

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

那么如何解决这个问题,两路:

  1. 如果你不需要这些audience-network-sdk做,只是将其删除。我的项目实际上并不需要它。
  2. 如果您还需要audience-network-sdkgoogle-analytics,请使用exclude group语法,如下面的代码片段所示。

    //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可以是任何其他的lib依赖于与其他库相同的库。这里只是想着如何解决类似的问题。

+0

完美的解决方案,让我可以确定重复的依赖关系来自哪里 –

+0

您也可以使用排除模块:'play-services''而不是'exclude group'命令。 – Sakiboy

+0

为了方便查找/搜索,在windows中使用以下命令 'gradlew -q app:dependencies> c:\ dependencies.log' –

1

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

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

我曾与这个问题很长一段time.My问题困惑是,虽然同样的错误日志中的问题略有不同。我希望我的sublib的buildtype与我的应用程序的buildtype相同。所以我在文档告诉我时为sublib分配了buildtype。 [Gradle插件用户指南] [1]

这是我得到的错误。

处理flavorCustomResource

错误:多个库com.xxx.libCommon

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

应用

- > LIB1 - > libCommon

- > LIB2 - > libCommon

我得到的错误,只有当我建立我的自定义buildtype.However,发布版本是好的。

更多细节。我的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的build.gradle分配的lib1 - > libCommon(自定义版本)不同的默认发布libCommon(发行版)。出现此错误。

我希望我的帖子能够帮助别人解决同一问题或给他/她一些提示。

+0

好的解释。它帮助我找到了类似的问题。对于我的内部库依赖项之一,我依赖于自定义生成类型的发行版本。 –

相关问题