Android Studio更新后,获取“找不到满足版本限制的'com.android.support:support-annotations'版本”

时间:2019-02-06 01:34:55

标签: android gradle android-studio-3.0

更新到最新版本后,我无法再构建APK,也无法理解gradle错误。

这是模块配置:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.myapp.mymodule"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 31
        versionName "2.07"
        project.archivesBaseName = "app-name_v" + defaultConfig.versionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'ch.acra:acra:4.9.2'

}

这是“构建”屏幕中显示的错误:

Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints: 
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'ch.acra:acra:4.9.2' --> 'com.android.support:support-annotations:24.1.1'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support.test:monitor:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support.test.espresso:espresso-core:3.0.2' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-vector-drawable:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:design:26.1.0' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:design:26.1.0' --> 'com.android.support:recyclerview-v7:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:design:26.1.0' --> 'com.android.support:transition:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-compat:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-media-compat:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-core-utils:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support:appcompat-v7:26.1.0' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-core-ui:26.1.0' --> 'com.android.support:support-annotations:26.1.0'
   Constraint path 'my-project:my-module:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0
   Constraint path 'my-project:my-module:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0
   Constraint path 'my-project:my-module:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0
   Constraint path 'my-project:my-module:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0

该应用程序可以完全构建而不会出错,并且可以在设备中运行而没有任何问题。

我已经尝试了Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints中的建议,但是其中任何一个对我都有效。

这是gradle.config:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

1 个答案:

答案 0 :(得分:1)

我想我没有正确注意。在构建日志中:

   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support.test:monitor:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
   Dependency path 'my-project:my-module:unspecified' --> 'com.android.support.test.espresso:espresso-core:3.0.2' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'

testImplementation使用的是该版本的较高版本。我删除了那些依赖关系,现在构建是正确的。我认为我需要设置较低版本的testImplementation以便将来重新使用。