簡體   English   中英

如何解決build.gradle中不同版本庫的錯誤?

[英]How to solve the error of different version of libraries in build.gradle?

我正在使用Android開發,並嘗試實現GPS和Google Map。

build.gradle(Module:app)類似於以下內容

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        multiDexEnabled true
        applicationId "com.app.t.pro"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    testCompile 'junit:junit:4.12'
}

但是它在compile 'com.android.support:appcompat-v7:26.+'時顯示錯誤。 錯誤是

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.1.0, 25.2.0. Examples include com.android.support:animated-vector-drawable:26.1.0 and com.android.support:mediarouter-v7:25.2.0 less... (Ctrl+F1) 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)

但是我在build.gradle沒有看到任何version-25 我錯過了什么嗎? 提前致謝。

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

compile 'com.google.android.gms:play-services-maps:11.4.2'
compile 'com.google.android.gms:play-services-location:11.4.2'

同時刪除

compile 'com.google.android.gms:play-services:11.4.2'

tl; dr您需要將Google Play庫更新到至少11.2+

查看Google Play發行說明

11.2中的SDK版本支持

將應用程序的Play服務依賴項升級到11.2.0或更高版本時,還必須更新應用程序的build.gradle以將compileSdkVersion指定為至少26(Android O)。 這不會改變您的應用程序的運行方式。 您將不需要更新targetSdkVersion。 如果您將compileSdkVersion更新為26,則可能會在構建中收到錯誤消息,其中包含以下消息,這些消息指向Android支持庫:

This support library should should not use a different version (25) than the compileSdkVersion (26).

可以通過將支持庫依賴性升級到至少26.0.0版本來解決此錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM