我正在更新我的应用以提供素材主题支持(我的应用使用Google Play服务)
当我同步我的项目时,显示出来了:
...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.11\res\values\wallet_colors.xml
Error:Attribute "showText" has already been defined
我的gradle依赖项:
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
// the latest version of play-services is 6.1.11
如果我排除appcompat-v7,那么项目编译时没有错误。
我是否对棒棒糖感到兴奋并没有正确阅读文档?我该如何解决这个问题?
构建脚本的一部分:
compileSdkVersion 21
buildToolsVersion '21.0.1'
dexOptions {
preDexLibraries true
//incremental true
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 11
versionName '1.0'
renderscriptTargetApi 21
renderscriptSupportMode true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
本地Google存储库如下所示:
答案 0 :(得分:20)
@igavran回答指向正确的方向,但我想提供更全面的答案,所以它是:
Gradle Resource Merger合并所有依赖项中的所有资源文件夹,并放入单个文件夹中。如果存在重复,则构建过程将失败。
出于某种奇怪的原因,Android Studio指向“消息”窗口中Google Play服务库的 wallet_colors.xml 。 Google Play服务与此问题无关。幸运的是,如果您在输出:标签下面看,您将找到解决问题的正确途径,例如。
您还可以从命令行构建项目并获得正确的路径。
在第172行的 values.xml 文件中(在您的情况下是不同的行),您会找到一个<declare-styleable>
,其属性名为“color”(“showText”在你的情况下)。最有可能是你自己的风格,你必须改变,以摆脱重复。
现在,当您知道原因时,可以在项目模块中找到该属性并用不同的名称替换它。我猜它会位于 /values/attrs.xml 文件中。
答案 1 :(得分:5)
我在同一个问题上花了最后两个小时,在我的情况下问题是我已经定义了自己的属性&#34; showText&#34; (在res / values / attrs.xml中)与<declare-styleable name="SwitchCompat">
中定义的属性冲突。
使用appcompat-v7:20但使用appcompat-v7:21构建失败时,此问题不存在。
答案 2 :(得分:1)
请勿使用以下示例1中的整个播放服务
示例1:编译'com.google.android.gms:play-services:7.5.0'
使用您要在应用程序中使用的那些服务。例如,如果您要使用Google+服务,请使用以下示例2
示例2:编译'com.google.android.gms:play-services-plus:7.5.0'
了解更多服务请访问:Setting Up Google Play Services