Android gradle依赖冲突和资源重复值

Posted

技术标签:

【中文标题】Android gradle依赖冲突和资源重复值【英文标题】:Android gradle dependencies conflicts and duplicate value for resource 【发布时间】:2019-04-16 02:54:13 【问题描述】:

以下是我的应用程序中的 gradle 依赖项

ext 
supportLibraryVersion = '27.1.1'
playServicesVersion = '16.0.0'
firebaseVersion = '16.0.4'

 dependencies 

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':pageIndicator')
implementation('io.branch.sdk.android:library:2.+') 
    exclude module: 'answers-shim'

implementation 'com.google.zxing:core:3.3.0'
implementation 'com.sothree.slidinguppanel:library:3.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

//Support library
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:support-v4:$supportLibraryVersion"
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support:customtabs:$supportLibraryVersion"
implementation "com.android.support:exifinterface:$supportLibraryVersion"
//Support library

//play services
implementation "com.google.android.gms:play-services-base:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation "com.google.android.gms:play-services-places:$playServicesVersion"
implementation "com.google.android.gms:play-services-location:$playServicesVersion"
implementation "com.google.android.gms:play-services-plus:$playServicesVersion"
implementation "com.google.android.gms:play-services-auth:16.0.1"
implementation "com.google.android.gms:play-services-analytics:16.0.5"
//play services

implementation 'com.android.volley:volley:1.1.1'
implementation 'com.flurry.android:analytics:7.0.0'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'

//firebase
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-analytics:16.0.5"
implementation "com.google.firebase:firebase-appindexing:16.0.2"
implementation "com.google.firebase:firebase-ads:17.1.0"
//firebase

implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
implementation 'com.clevertap.android:clevertap-android-sdk:3.1.4'
implementation 'com.ncapdevi:frag-nav:2.4.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.evernote:android-job:1.1.11'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
implementation 'com.bigbangbutton:editcodeview:1.0.5'
implementation 'com.facebook.android:facebook-login:4.30.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.koushikdutta.async:androidasync:2.+'
implementation 'org.java-websocket:Java-WebSocket:1.3.7'
implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
implementation 'com.google.code.gson:gson:2.8.2'

我在构建时收到以下错误消息 请通过更新 google-services 插件的版本(有关最新版本的信息可在 https://bintray.com/android/android-tools/com.google.gms.google-services/ 获得)或将 com.google.android.gms 的版本更新为 16.0.0 来解决版本冲突。

尝试运行以下命令查看依赖树

gradle dependencies --configuration compile

以下是命令的输出

\--- com.google.firebase:firebase-core:16.0.0
 +--- com.google.firebase:firebase-analytics:16.0.0
 |    +--- com.google.android.gms:play-services-basement:15.0.1
 |    |    \--- com.android.support:support-v4:26.1.0
 |    |         +--- com.android.support:support-compat:26.1.0
 |    |         |    +--- com.android.support:support-annotations:26.1.0
 |    |         |    \--- android.arch.lifecycle:runtime:1.0.0
 |    |         |         +--- android.arch.lifecycle:common:1.0.0
 |    |         |         \--- android.arch.core:common:1.0.0
 |    |         +--- com.android.support:support-media-compat:26.1.0
 |    |         |    +--- com.android.support:support-annotations:26.1.0
 |    |         |    \--- com.android.support:support-compat:26.1.0 (*)
 |    |         +--- com.android.support:support-core-utils:26.1.0
 |    |         |    +--- com.android.support:support-annotations:26.1.0
 |    |         |    \--- com.android.support:support-compat:26.1.0 (*)
 |    |         +--- com.android.support:support-core-ui:26.1.0
 |    |         |    +--- com.android.support:support-annotations:26.1.0
 |    |         |    \--- com.android.support:support-compat:26.1.0 (*)
 |    |         \--- com.android.support:support-fragment:26.1.0
 |    |              +--- com.android.support:support-compat:26.1.0 (*)
 |    |              +--- com.android.support:support-core-ui:26.1.0 (*)
 |    |              \--- com.android.support:support-core-utils:26.1.0 (*)
 |    +--- com.google.android.gms:play-services-measurement-base:[15.0.4] -> 15.0.4
 |    +--- com.google.android.gms:play-services-stats:15.0.1
 |    |    \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
 |    +--- com.google.firebase:firebase-analytics-impl:[16.0.0] -> 16.0.0
 |    |    +--- com.google.android.gms:play-services-ads-identifier:15.0.1
 |    |    |    \--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
 |    |    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
 |    |    +--- com.google.android.gms:play-services-measurement-base:[15.0.4] -> 15.0.4
 |    |    +--- com.google.android.gms:play-services-stats:15.0.1 (*)
 |    |    +--- com.google.android.gms:play-services-tasks:15.0.1
 |    |    |    \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
 |    |    +--- com.google.firebase:firebase-common:16.0.0
 |    |    |    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
 |    |    |    \--- com.google.android.gms:play-services-tasks:15.0.1 (*)
 |    |    \--- com.google.firebase:firebase-iid:16.0.0
 |    |         +--- com.google.android.gms:play-services-basement:15.0.1 (*)
 |    |         +--- com.google.android.gms:play-services-stats:15.0.1 (*)
 |    |         +--- com.google.android.gms:play-services-tasks:15.0.1 (*)
 |    |         +--- com.google.firebase:firebase-common:16.0.0 (*)
 |    |         \--- com.google.firebase:firebase-iid-interop:16.0.0
 |    |              +--- com.google.android.gms:play-services-base:15.0.1
 |    |              |    +--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
 |    |              |    \--- com.google.android.gms:play-services-tasks:[15.0.1] -> 15.0.1 (*)
 |    |              \--- com.google.android.gms:play-services-basement:15.0.1 (*)
 |    \--- com.google.firebase:firebase-common:16.0.0 (*)
 \--- com.google.firebase:firebase-measurement-connector-impl:16.0.0
      +--- com.google.android.gms:play-services-basement:15.0.1 (*)
      +--- com.google.android.gms:play-services-measurement-base:[15.0.4] -> 15.0.4
      +--- com.google.firebase:firebase-analytics:[16.0.0] -> 16.0.0 (*)
      +--- com.google.firebase:firebase-analytics-impl:[16.0.0] -> 16.0.0 (*)
      +--- com.google.firebase:firebase-common:16.0.0 (*)
      \--- com.google.firebase:firebase-measurement-connector:16.0.0
           \--- com.google.android.gms:play-services-basement:15.0.1 (*)

(*) - 省略依赖项(之前列出)

不知道冲突的确切位置以及如何解决?

通过如下更新主 gradle 文件解决了这个问题

buildscript 
repositories 
    jcenter()
    google()


dependencies 
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files



 allprojects 
repositories 
    jcenter()
    maven  url "https://jitpack.io" 
    maven 
        url "http://dl.bintray.com/piasy/maven"
    
    maven  url "https://oss.sonatype.org/content/repositories/snapshots/" 
    google()



task clean(type: Delete) 
   delete rootProject.buildDir

现在遇到以下问题

错误:资源“attr/fontStyle”的值与配置“”重复。 app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:1421: 错误:资源之前在这里定义。

【问题讨论】:

我试图解决这个问题... 3 天没有答案 你是什么 com.google.gms:google-services 在应用程序(项目级别)build.gradle 中的版本? 您从依赖项中提供了库列表。但是 google-services 插件的版本是多少? 使用 16.0.0 版本 【参考方案1】:

看起来像

com.google.firebase:firebase-analytics

使用 com.google.android.gms:play-services-tasks:15.0.1

请更新 Firebase。尝试使用

com.google.firebase:firebase-analytics:+

下一步是强制配置:

android
    configurations.all 
    resolutionStrategy.force "com.google.android.gms:play-services-tasks:$playServicesVersion"
    

请检查您的构建 gradle 版本并更新 com.android.tools.build:gradle

【讨论】:

获取错误找不到依赖项“com.google.android.gms:play-services-tasks:16.0.0” 检查***.com/questions/50940565/… 合并错误。dir\values\values.xml:621: 错误:资源 'attr/fontStyle' 与配置 '' 的重复值。 更新android构建工具到28.0.3和android编译版本到28 仍有问题【参考方案2】:

更新的主 gradle 文件解决了这个冲突更新了 com.android.tools.build:gradle 和 com.google.gms:google-services 版本

buildscript 
repositories 
    jcenter()
    google()


dependencies 
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

 

allprojects 
repositories 
    jcenter()
    maven  url "https://jitpack.io" 
    maven 
        url "http://dl.bintray.com/piasy/maven"
    
    maven  url "https://oss.sonatype.org/content/repositories/snapshots/" 
    google()

 

 task clean(type: Delete) 
delete rootProject.buildDir
 

【讨论】:

以上是关于Android gradle依赖冲突和资源重复值的主要内容,如果未能解决你的问题,请参考以下文章

处理Gradle依赖冲突

终极方案:快速解决Android项目依赖冲突

gradle 解决重复依赖

Android Gradle 插件Gradle 依赖管理 ⑥ ( dependencies 依赖查找路径 | dependencies 依赖冲突 | dependencies 依赖库层级分析 )

Gradle打包冲突,exclude依赖

Android Gradle 插件Android 依赖管理 ⑥ ( 依赖冲突处理 | transitive 依赖传递设置 | exclude 依赖排除设置 | force 强制指定依赖库 )