如何解决android中的版本冲突错误()

今日长缨在手,何时缚住苍龙。这篇文章主要讲述如何解决android中的版本冲突错误?相关的知识,希望能为你提供帮助。

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 27 buildToolsVersion "27.0.3" defaultConfig { applicationId "xxxxxxxxxxxxxxxxxxx" minSdkVersion 19 targetSdkVersion 27 versionCode 20 versionName '6.7' multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" useLibrary 'org.apache.http.legacy' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } dexOptions { javaMaxHeapSize "4g"} } productFlavors { } }dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile files('libs/droidText.0.2.jar') compile files('libs/mail.jar') compile files('libs/activation.jar') compile files('libs/additionnal.jar') // compile files('libs/gson-2.2.2.jar') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) testCompile 'junit:junit:4.12' compile 'com.loopj.android:android-async-http:1.4.9' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.mcxiaoke.volley:library-aar:1.0.0' compile 'com.android.support:recyclerview-v7:27.1.0' compile 'com.android.support:appcompat-v7:27.1.0' compile 'com.android.support:design:27.1.0' compile 'com.android.support:support-core-utils:27.1.0' compile 'com.android.support:support-compat:27.1.0' compile 'com.android.support:multidex:1.0.1' // Glide image library compile 'com.google.firebase:firebase-messaging:11.0.4' compile 'com.google.android.gms:play-services-location:11.6.0' compile 'com.google.android.gms:play-services-places:11.6.0' compile 'com.google.android.gms:play-services-maps:11.6.0' //implementaion 'com.google.android.gms:play-services:9.0.0' compile 'com.google.code.gson:gson:2.6.2' compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'com.wdullaer:materialdatetimepicker:2.3.0' compile 'com.github.bumptech.glide:glide:3.7.0' testCompile 'junit:junit:4.12' compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' compile('org.apache.httpcomponents:httpmime:4.3') { exclude module: "httpclient" } compile('com.google.code.gson:gson:2.2.2') { exclude module: "com.google.code.gson" } } allprojects { repositories { jcenter() maven { url "https://maven.google.com" } } } android { packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' exclude 'META-INF/dependencies.txt' exclude 'META-INF/LGPL2.1' exclude 'META-INF/ASL2.0' exclude '.idea/compiler.xml' } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 }defaultConfig { multiDexEnabled true}}

在这里,我用firebase和Gradle相关库定义了play service。以前我使用的是Firebase 9.0.0版本,现在还没有使用firebase密钥。所以我已经更新到新版本,然后开始遇到问题。首先我只更新了firebase库,但错误显示为playservice,firebase必须保持相同的版本。问题是playservice相关的gradle更改时间。 (错误:任务执行失败':app:processDebugGoogleServices'。
请通过更新google-services插件的版本(有关最新版本的信息可在https://bintray.com/android/android-tools/com.google.gms.google-services/获取)或将com.google.android.gms的版本更新为9.0.0来修复版本冲突。 )
答案【如何解决android中的版本冲突错误()】谷歌服务插件问题是因为你使用不同版本的firebase和谷歌播放服务:
compile 'com.google.firebase:firebase-messaging:11.0.4' compile 'com.google.android.gms:play-services-location:11.6.0' compile 'com.google.android.gms:play-services-places:11.6.0' compile 'com.google.android.gms:play-services-maps:11.6.0'

它应该是:
compile 'com.google.firebase:firebase-messaging:11.6.0' compile 'com.google.android.gms:play-services-location:11.6.0' compile 'com.google.android.gms:play-services-places:11.6.0' compile 'com.google.android.gms:play-services-maps:11.6.0'

然后,您还需要将apply plugin: 'com.google.gms.google-services'移动到构建gradle的底部,如下所示:
apply plugin: 'com.android.application' android { ... }...dependencies { ... }apply plugin: 'com.google.gms.google-services'

您还需要仅使用一个版本的依赖项。在您正在使用的项目中:
compile 'com.google.code.gson:gson:2.6.2'compile('com.google.code.gson:gson:2.2.2') { exclude module: "com.google.code.gson" }

这是多余的。你只需要使用一个:
compile 'com.google.code.gson:gson:2.6.2'

最后,您不需要添加以下内容:
compile files('libs/droidText.0.2.jar') compile files('libs/mail.jar') compile files('libs/activation.jar') compile files('libs/additionnal.jar')

因为以下行已包含所有这些:
compile fileTree(include: ['*.jar'], dir: 'libs')


    推荐阅读