问题
I'm receiving an error due to the fact I'm attempting to use the app indexing library from Google while also importing a library which uses an older version of the android gms library for a different component - the cast library from Google Play services. The error states " All com.google.android.gms libraries must use the exact same version specification(mixing versions can lead to runtine crashes). Found versions 8.30,7.80. Examples include com.google.android.gms:play-servics-appindexing:8.3.0 and com.google.android.gms:play-services-cast:7.8.0. Not sure how to fix this as I cannot update the version used in the connectsdk I'm importing and I require version 8.3.0 for app indexing. My gradle files are as follows:
Module
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId xxx.xxx.xxx.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 10005
versionName "1.0.5"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-lang3-3.3.2.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile 'com.android.support:multidex:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-appindexing:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile ('com.connectsdk:connect-sdk-android:1.6.+')
**Project**:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
回答1:
You can always tell Gradle to use the latest version of a dependency; it'll automatically override whatever your transitive dependencies request. E.g., if this is in your build.gradle
:
compile 'com.google.android.gms:play-services-cast:8.3.0'
compile 'com.connectsdk:connect-sdk-android:1.6.0'
Even though connect-sdk-android v1.6.0 uses play-services-cast v7.8.0, you'll still get 8.3.0 in your final build.
That said, if Connect SDK's library doesn't work with 8.3.0, then you're stuck until they update their library anyways. In that case, you might want to inform them of the problem on their library's issue page.
来源:https://stackoverflow.com/questions/34210199/android-dependency-issue-with-gms-play-services