添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

错误:任务':app:preDebugAndroidTestBuild'的执行失败,当试图在android studio中运行java程序时。

15 人关注

在android studio中运行java程序时,得到以下错误。

错误:任务执行失败'。 app:preDebugAndroidTestBuild '.

与项目':app'中的依赖'com.android.support:support-annotations'发生冲突。应用程序(26.1.0)和测试应用程序(27.1.1)的已解决版本不同。参见 https://d.android.com/r/tools/test-apk-dependency-conflicts.html 详情请见下文。

请提供任何解决方案。?

2 个评论
为此,你必须看一下你的依赖关系,确保没有这些冲突。如果你想让我们帮助你,公布你的依赖关系会有帮助。
我也有同样的问题。这很荒唐。 这是一个全新的项目。 为什么会出现这种情况呢!?Android Studio 3.0.1
java
android
Kms
Kms
发布于 2018-04-30
14 个回答
Nazmus Saadat
Nazmus Saadat
发布于 2018-05-13
已采纳
0 人赞同

使用【替换代码0 而不是 implementation 'com.android.support:appcompat-v7:26.1.0' ,并将compileSdkV版本26改为27

E235
I also updated com.android.support to 27: implementation 'com.android.support:design:27.1.1' and targetSdkVersion to 27.
如果我想继续使用SDK 26怎么办?这可能吗?
mahmoud zaher
mahmoud zaher
发布于 2018-05-13
0 人赞同

感谢@Ganesh Bhat和Chad Bingham

对于那些仍然面临问题的人来说,上述答案在和roid studio 2.2 Preview中没有帮助我。

This fixed my issue.

把这个添加到你的gradle文件中。

configurations.all {
  resolutionStrategy {
    force 'com.android.support:support-annotations:23.1.1'

Reference: https://github.com/JakeWharton/u2020/blob/05a57bf43b9b61f16d32cbe8717af77cd608b0fb/build.gradle#L136-L140

更新到23.3.0后,安卓支持库出错

应用程序(22.0.0)和测试应用程序(21.0.3)的已解决版本不同

- 如果前面的答案不奏效:

你应该更新compileSdkVersion呼叫中心 to the latest update till now compileSdkVersion is 27 , also 呼叫中心 is 27.1.1和 28.0.0-alpha1 is a pre-release version

compileSdkVersion 27

implementation 'com.和roid.support:呼叫中心-v7:26.1.0'

到最新更新

implementation 'com.和roid.support:呼叫中心-v7:27.1.1'

你可以从这个链接查看最新的更新。

https://developer.和roid.com/topic/libraries/support-library/revisions

关于品脱的回答:)
E235
I also updated com.android.support to 27: implementation 'com.android.support:design:27.1.1' and targetSdkVersion to 27.
完美的答案,第一次尝试就成功了
Khemraj Sharma
Khemraj Sharma
发布于 2018-05-13
0 人赞同
Kms
太好了!!!。谢谢你。
你也可以通过加注或标记来表示你的感谢 :)
@SrujanBarai 你可以参考上面的相关答案。
Mohammed mansoor
Mohammed mansoor
发布于 2018-05-13
0 人赞同

在你的应用程序gradle文件中加入以下内容

configurations.all {
   resolutionStrategy {
      force 'com.android.support:support-annotations:26.1.0'
    
Ashana.Jackol
Ashana.Jackol
发布于 2018-05-13
0 人赞同

在你的 应用程序的依赖性 大括号。

android{
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'

最新的是27.1.1,到现在为止。

Anandharaj R
Anandharaj R
发布于 2018-05-13
0 人赞同

AS配置版本。

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'**

Modify:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.0.0-beta1'
testImplementation 'junit:junit:4.12'
**androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'**
    
Mohammed Fuzail
Mohammed Fuzail
发布于 2018-05-13
0 人赞同

好吧,我也面临着同样的问题,下面是我如何解决的。

  • Goto app level Gradle file
  • 在那里你会发现你所设置的所有配置是什么。就我而言,这里

    android{
        **compileSdkVersion 26**
        defaultConfig {
            applicationId "com.xxxxxxxxxxx.yyyyyyyy.zzz"
            minSdkVersion 19
            **targetSdkVersion 26**
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    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'
    

    So here just change the compileSdkVersion & targetSdkVersion from 26 to 27

    从依赖关系改变支持appcomat

    from   implementation 'com.android.support:appcompat-v7:26.1.0' 
    to     implementation 'com.android.support:appcompat-v7:27.1.1'
    android {
        **compileSdkVersion 27**
        defaultConfig {
            applicationId "com.xxxxxxxxxxx.yyyyyyyy.zzz"
            minSdkVersion 19
            **targetSdkVersion 27**
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        **implementation 'com.android.support:appcompat-v7:27.1.1'**
        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'
    

    Got Fixed !!!

    这个答案很清楚,可以帮助在Udemy上安装Android Studio 3.0.1的Android Oreo课程。
    Hemn Hamza
    Hemn Hamza
    发布于 2018-05-13
    0 人赞同

    你好,我也有同样的问题,为了解决这个问题,你需要把你的应用程序bulid gradle中的appcompat改为

    implementation 'com.android.support:appcompat-v7:27.1.1'

    然后,它应该要求你安装它,如果你没有安装,如果仍然错误没有解决,改变你的sdk版本,这将有很大的帮助,因为如果你改变appcompact到27.1.1,你需要改变你的sdk版本到27。 我建议所有的人把你的android studio和sdk更新到最新的版本,因为如果你把appcompact改为27.1.1,你也需要把你的sdk版本改为27。

    deadpool
    deadpool
    发布于 2018-05-13
    0 人赞同

    如果对你有帮助,请尝试以下变化

    com.android.support:appcompat-v7:26.1.0

    com.android.support:appcompat-v7:27.1.1

    这个异常通常是在appcompat版本和编译版本不一致的时候抛出的,试着让两者处于同一版本。
    Ready Android
    Ready Android
    发布于 2018-05-13
    0 人赞同

    Error:

    错误:任务':app:preDebugAndroidTestBuild'的执行失败。

    与项目':app'中的依赖项'com.android.support:support-annotations'发生冲突。应用程序(26.1.0)和测试应用程序(27.1.1)的已解决版本不同。 (27.1.1)不同。参见 https://d.android.com/r/tools/test-apk-dependency-conflicts.html 以了解 详细情况。

    这是因为你的应用程序build.gradle中没有添加依赖项,或者可能是一个旧版本。因此,请添加一个注释支持的依赖。

    implementation 'com.android.support:support-annotations:27.1.1'
    

    在这里我添加了注释版本27.1.1来解决你的错误,如果这与不同的版本不匹配,那么就把它改为所需的版本。

    Khemraj Sharma
    Khemraj Sharma
    发布于 2018-05-13
    0 人赞同

    我发现这非常容易。

    我们将使用更新,并对所有模块使用同一版本。

    1. Go to project level build.gradle , use global variables

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        ext.kotlinVersion = '1.2.61'
        ext.global_minSdkVersion = 16
        ext.global_targetSdkVersion = 28
        ext.global_buildToolsVersion = '28.0.1'
        ext.global_supportLibVersion = '27.1.1'
    

    2. Go to app level build.gradle, and use global variables

    app level build.gradle

    android {
        compileSdkVersion global_targetSdkVersion
        buildToolsVersion global_buildToolsVersion
        defaultConfig {
            minSdkVersion global_minSdkVersion
            targetSdkVersion global_targetSdkVersion
    dependencies {
        implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
        implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
        // and so on...
    

    一些库/模块 【替换代码0

    android {
        compileSdkVersion global_targetSdkVersion
        buildToolsVersion global_buildToolsVersion
        defaultConfig {
            minSdkVersion global_minSdkVersion
            targetSdkVersion global_targetSdkVersion
    dependencies {
        implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
        implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
        // and so on...
    

    解决办法是使你的版本与所有模块中的相同。这样,你就不会有冲突了。

    Tips for future

    我觉得当我更新了所有东西的版本--gradle、sdks。 库等,那么我面临的错误就会减少。因为开发人员正在努力 努力使其在Android Studio上轻松开发。

    始终拥有**最新的但稳定的版本**不稳定的版本是alphabetarc,在开发时请忽略它们。

    我已经在我的项目中更新了以下所有内容,并且感觉编码无懈可击。

  • Update Android Studio (Track release)
  • Project level build.gradle - classpath 'com.android.tools.build:gradle:3.2.0' (Track android.build.gradle release & this)
  • Have updated buildToolVersion (Track buildToolVersion release)
  • Have latest compileSdkVersion and targetSdkVersion Track platform release
  • Have updated library versions, because after above updates, its necessary. (@See How to update)
  • 编码快乐!:)

    dungu
    dungu
    发布于 2018-05-13
    0 人赞同

    也要看看这个,在你的gradle中

    targetSdkVersion 27
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
        
    Ayanfe
    Ayanfe
    发布于 2018-05-13
    0 人赞同

    Go to settings>editor> Then check those two boxes as displayed in the image. It should solve it without any issue.

    SHISHIR
    SHISHIR
    发布于 2018-05-13
    0 人赞同

    将此代码添加到应用程序级别的build.gradle的底部。它将会起作用...

    configurations.all {
        resolutionStrategy.eachDependency{
            DependencyResolveDetails details ->
                def requested=details.requested
                if(requested.group=="com.android.support"){
                if(!requested.name.startsWith("multidex")){
                    details.useVersion("26.0.1")