Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 与依赖冲突';support:supportannotations';在项目&x27;中:应用程序&x27;。应用程序(26.1.0)和测试应用程序(27.1.1)的解析版本不同。_Android - Fatal编程技术网

Android 与依赖冲突';support:supportannotations';在项目&x27;中:应用程序&x27;。应用程序(26.1.0)和测试应用程序(27.1.1)的解析版本不同。

Android 与依赖冲突';support:supportannotations';在项目&x27;中:应用程序&x27;。应用程序(26.1.0)和测试应用程序(27.1.1)的解析版本不同。,android,Android,我是Android应用程序开发新手。当我试图创建一个新的项目,Android项目时…弹出了以下消息 错误:任务“:app:preDebugAndroidTestBuild”的执行失败 与依赖项“com.android.support”冲突:支持注释“在项目中”:应用程序。应用程序(26.1.0)和测试应用程序(27.1.1)的解析版本不同。有关详细信息,请参阅。 信息:渐变任务[:app:generateDebugSources,:app:generateDebugAndroidTestSour

我是Android应用程序开发新手。当我试图创建一个新的项目,Android项目时…弹出了以下消息

错误:任务“:app:preDebugAndroidTestBuild”的执行失败

与依赖项“com.android.support”冲突:支持注释“在项目中”:应用程序。应用程序(26.1.0)和测试应用程序(27.1.1)的解析版本不同。有关详细信息,请参阅。 信息:渐变任务[:app:generateDebugSources,:app:generateDebugAndroidTestSources,:app:mockableAndroidJar]

这是我项目的截图

我还尝试将此代码添加到我的依赖项中。。 androidTestCompile'com.android.support:支持注释:23.3.0' 这没有成功。我也试过27.1.1和26.1.0。。
根据你的截图,我找到了两个可行的解决方案:

第一个解决方案:将此行添加到gradle模块的依赖项中

compile 'com.android.support:support-annotations:27.1.1'
并同步您的项目

注意:如果您使用的是Android studio 3+将
编译
更改为
实现

第二种解决方案:配置文档中的项目范围属性

在project gradle中添加以下行:

// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
    // The following are only a few examples of the types of properties you can define.
    compileSdkVersion = 26
    // You can also use this to specify versions for dependencies. Having consistent
    // versions between modules can avoid behavior conflicts.
    supportLibVersion = "27.1.1"
}
implementation 'com.android.support:appcompat-v7:27.1.1'
然后,要访问此部分,请将
compileSdkVersion
行更改为

compileSdkVersion rootProject.ext.compileSdkVersion

dependencies
部分,将导入的库更改为:

compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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 'com.android.support:support-annotations:27.1.1'
}
并同步您的项目

注意:如果您使用的是Android studio 3+将
编译
更改为
实现

有关
compile
implementation
之间的区别,请查看以下内容

这是由于版本冲突造成的,要解决此问题,只需强制更新您的支持注释版本,并在模块上添加以下行:app gradle

implementation('com.android.support:supportannotations:27.1.1')

希望这能解决您的问题;)

编辑

几乎忘记了,您可以为版本声明一个额外的属性(),转到您的项目(或顶部)gradle文件,并声明您的支持,或者仅在本例中,声明注释版本var

ext.annotation\u version=“27.1.1”

然后在您的模块中,将其替换为:

实现(“com.android.support:支持注释:$annotation\u version”)


这与@emadabel解决方案非常相似,这是一个很好的替代方案,但没有块,也没有
rootproject
前缀。

将此添加到build.gradle(模块应用程序)中对我有效:

编译'com.android.support:support annotations:27.1.1'解决此问题的另一个简单方法是编辑您的
build.gradle
(应用程序):

  • 转到android
  • 标记并将
    编译DK26版
    更改为
    编译DK27版
  • 转到
    defaultConfig
    标记并将
    targetSdkVersion 26
    更改为
    targetSdkVersion 27
  • 转到
    依赖项
    标记并更改
    实现'com.android.support:appcompat-v7:26.1.0'
    实现'com.android.support:appcompat-v7:27.1.1'

  • 在app.gradle文件中的Dependencies块之前添加以下行

    configurations.all {
        resolutionStrategy {
            force 'com.android.support:support-annotations:26.1.0'
        }
    }
    
    为了更好地理解,下面还有一个屏幕截图

  • 只有当您希望目标sdk为26时,configurations.all块才有帮助。如果可以将其更改为27,则错误将消失,而无需在app.gradle文件中添加配置块

  • implementation 'com.android.support:support-annotations:27.1.1'
    
  • 如果您要从app.gradle文件中删除所有测试实现,还有一种方法可以解决此错误,而且您不需要添加配置块,也不需要更改targetsdk版本


  • 希望有帮助。

    别担心,这很简单:

    进入“项目”目录结构,进入“Gradle脚本”,然后进入其中的“build.Gradle(模块:app)”并双击它。

    现在- 向下滚动程序,并在其中转到依赖项部分: 如下


    依赖关系{

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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 fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    
    }


    现在,删除最后两行代码并重建应用程序,现在它就可以工作了

    依赖项应为:


    依赖关系{

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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 fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    
    }



    重新构建应用程序,它就能正常工作

    如果更改目标sdk版本没有帮助,那么如果您与版本
    3.0.2
    有任何依赖关系,则将其更改为
    3.0.1

    e、 g变化

    androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
    


    我也有同样的问题,在build.gradle(模块:app)中 在依赖项中添加以下代码行:

    dependencies 
    {
       ...
       compile 'com.android.support:support-annotations:27.1.1'
    }
    
    它对我非常有效

    转到您项目中的build.gradle(模块应用程序):

    按照图片进行操作并更改这些版本:

    compileSdkVersion: 27
    targetSdkVersion: 27
    
    如果android studio版本2: 使用此行更改行:

    compile 'com.android.support:appcompat-v7:27.1.1'
    
    否则 使用此行更改行:

    // This block encapsulates custom properties and makes them available to all
    // modules in the project.
    ext {
        // The following are only a few examples of the types of properties you can define.
        compileSdkVersion = 26
        // You can also use this to specify versions for dependencies. Having consistent
        // versions between modules can avoid behavior conflicts.
        supportLibVersion = "27.1.1"
    }
    
    implementation 'com.android.support:appcompat-v7:27.1.1'
    

    如果您使用的是Android Studio 3.1+或更高版本,希望您能解决您的bug。

    把这个放在你的gradle Dependencies中:

    implementation 'com.android.support:support-annotations:27.1.1'
    
    总的来说是这样的:

    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        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 'com.android.support:support-annotations:27.1.1'
    }
    

    中解释了更好的解决方案。我把以前给出的答案放在横线下

    根据那里的解决方案:

    使用外部标记并在顶级build.gradle文件中写下以下代码。您要将版本更改为变量,而不是静态版本号

    ext {
        compileSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    
    更改应用程序级别build.gradle文件中的静态版本号,该文件附近有
    (模块:app)

    android {
        compileSdkVersion rootProject.ext.compileSdkVersion // It was 26 for example
        // the below lines will stay
    }
    
    // here there are some other stuff maybe
    
    dependencies {
        implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
        // the below lines will stay
    }
    
    同步您的项目,您将不会收到任何错误


    您不需要向Gradle脚本添加任何内容。安装必要的传感和诊断模块,故障将被排除
    implementation 'com.android.support:support-annotations:27.1.1'