Ошибка gradle для Android: все библиотеки com.android.support должны использовать одинаковую спецификацию версии? - PullRequest
0 голосов
/ 20 июня 2019

Вы найдете десятки вопросов с таким же названием в stackoverflow.К сожалению, ни одна из них не решила мою проблему.

Я получил следующую ошибку:

Все библиотеки com.android.support должны использовать одну и ту же спецификацию версии (смешивание версий может привести к сбоям во время выполнения).Найдено версии 26.1.0, 25.3.1.Примеры включают com.android.support:support-compat:26.1.0 и com.android.support:animated-vector-drawable:25.3.1

в этой строке (приложение модуля):

compile "com.android.support:appcompat-v7:$android_support_version"

Но я не понимаю, почему?Где я могу использовать версию 26.1.0?

Вот мои файлы (файл проекта):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        android_support_version ="25.3.1"
        archVersion = "1.0.0-alpha3"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Модуль приложения:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.bsobat.github"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    dataBinding {
        enabled = true
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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:$android_support_version"
    compile "com.android.support:support-v13:$android_support_version"
    compile "com.android.support:design:$android_support_version"
    compile "com.android.support:recyclerview-v7:$android_support_version"
    compile "com.android.support:cardview-v7:$android_support_version"

    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    testCompile 'junit:junit:4.12'

    //dagger2
    compile "com.google.dagger:dagger:2.9"
    annotationProcessor "com.google.dagger:dagger-compiler:2.9"
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'javax.inject:javax.inject:1'


    //android arch. component
    compile "android.arch.lifecycle:runtime:$archVersion"
    compile "android.arch.lifecycle:extensions:$archVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$archVersion"
    compile "android.arch.persistence.room:runtime:$archVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$archVersion"

    //Retrofit
    compile 'com.squareup.retrofit2:retrofit:2.2.0'

    //OkHttp
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.okio:okio:1.7.0'

    //Gson
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'

    //Glide
    compile 'com.github.bumptech.glide:glide:4.0.0-RC0'


    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile("android.arch.core:core-testing:$archVersion", {
        exclude group: 'com.android.support', module: 'support-compat'
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-core-utils'
    })

}

1 Ответ

0 голосов
/ 21 июня 2019

Вам необходимо добавить нижеприведенный блок кода внизу вашего файла уровня приложения.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...