【问题标题】:Error:Execution failed for task ':app:preDebugAndroidTestBuild' , when tried to run java program in android studio错误:任务 ':app:preDebugAndroidTestBuild' 执行失败,当尝试在 android studio 中运行 java 程序时
【发布时间】:2018-10-09 21:28:51
【问题描述】:

在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

请提供任何解决方案。 ?

【问题讨论】:

  • 为此,您必须查看您的依赖项并确保没有这些冲突。如果您希望我们为您提供帮助,这将有助于发布您的依赖项。
  • 我遇到了同样的问题。这是荒唐的。 这是一个全新的项目。 为什么会发生这种情况?! Android Studio 3.0.1

标签: java android


【解决方案1】:

使用implementation 'com.android.support:appcompat-v7:27.1.1' 而不是 implementation 'com.android.support:appcompat-v7:26.1.0' 并将 compileSdkVersion 26 更改为 27

【讨论】:

  • 我还将com.android.support 更新为27:implementation 'com.android.support:design:27.1.1'targetSdkVersion 更新为27。
  • 如果我想继续使用 SDK 26 怎么办?有可能吗?
【解决方案2】:

感谢@Ganesh Bhat 和 Chad Bingham

对于那些仍然面临问题的人,以上答案在 android studio 2.2 Preview 中对我没有帮助。

这解决了我的问题。

将此添加到您的 gradle 文件中。

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

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

Android support library error after updating to 23.3.0

Resolved versions for app (22.0.0) and test app (21.0.3) differ


更新 - 如果上一个答案不起作用:

您应该将 compileSdkVersionappcompat 更新到最新的更新,直到现在 compileSdkVersion 为 27 , appcompat 也是 27.1.1 和 28.0.0-alpha1 是预发布版本

因此

改变

compileSdkVersion 27

实现'com.android.support:appcompat-v7:26.1.0'

最新更新

实现'com.android.support:appcompat-v7:27.1.1'

您可以从此链接查看最新更新:

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

【讨论】:

  • 一品脱答案:)
  • 我还将com.android.support 更新为27:implementation 'com.android.support:design:27.1.1'targetSdkVersion 更新为27。
  • 完美答案,第一次尝试成功
【解决方案3】:

【讨论】:

  • 太棒了!!谢谢。
  • 您也可以通过点赞或标记来表示感谢:)
  • @SrujanBarai 你可以参考上面的相关答案。
【解决方案4】:

将此添加到您的应用 gradle 文件中

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

【讨论】:

    【解决方案5】:

    将这些行添加到您的 应用依赖项 大括号中,

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

    到目前为止,最新的是 27.1.1。

    【讨论】:

      【解决方案6】:

      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'**
      

      修改:

      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'**
      

      【讨论】:

        【解决方案7】:

        好吧,我也遇到了同样的问题,我是如何解决的

        • 转到应用级 Gradle 文件

        在那里你会找到你设置的所有配置。就我而言

        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'
        }
        

        所以这里只需将 compileSdkVersion 和 targetSdkVersion 从 26 更改为 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'
        }
        

        解决了!!!

        【讨论】:

        • 这个答案很明确,有助于为 Udemy 上的 Android Oreo 课程安装 Android Studio 3.0.1。
        【解决方案8】:

        大家好,我在解决这个问题时遇到了同样的问题,你需要在你的应用程序 bulid gradle 中将你的 appcompat 更改为

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

        然后它应该要求你安装它如果你还没有安装如果仍然错误没有解决改变你的 sdkversions 这将有很大帮助因为如果你改变 appcompact 到 27.1.1,您还需要将 sdkversion 更改为 27,我建议大家将您的 android studio 和 sdk 更新到最新

        【讨论】:

          【解决方案9】:

          如果对您有帮助,请尝试以下更改

          com.android.support:appcompat-v7:26.1.0

          com.android.support:appcompat-v7:27.1.1

          【讨论】:

          • 这个异常通常在appcompat版本和编译版本不同的时候抛出尝试使两者在同一版本上。
          【解决方案10】:

          错误:

          错误:任务 ':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 为 详情。

          这是因为您的 App build.gradle 没有添加依赖项,或者可能是它的旧版本。所以,添加一个注解支持的依赖项。

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

          这里我添加了注释版本 27.1.1 来解决您的错误,如果这与不同的版本不匹配,然后将其更改为所需的版本。

          【讨论】:

            【解决方案11】:

            我发现这很容易。

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

            1。转到项目级别build.gradle,使用全局变量

            // 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。转到应用级别build.gradle,并使用全局变量

            应用级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...
            }
            

            一些库/模块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...
            }
            

            解决方案是使您的版本与所有模块中的版本相同。以免发生冲突。

            未来提示

            当我更新了所有东西的版本——gradle、sdks、 图书馆等然后我面临的错误更少。因为开发人员正在工作 很难在 Android Studio 上轻松开发。

            总是有**最新的但稳定的版本**不稳定的版本是alphabetarc,开发时忽略它们。

            我在我的项目中更新了以下所有内容,感觉编码完美无瑕。

            编码愉快! :)

            【讨论】:

              【解决方案12】:

              在你的 gradle 中看看这个也很重要

              targetSdkVersion 27
              compileSdkVersion 27
              buildToolsVersion '27.0.3'
              

              【讨论】:

                【解决方案13】:

                转到设置>编辑器>然后选中图像中显示的这两个框。它应该可以毫无问题地解决它。

                【讨论】:

                  【解决方案14】:

                  将此代码添加到应用级别的 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")
                              }
                          }
                      }
                  }
                  

                  【讨论】:

                    猜你喜欢
                    • 2016-02-09
                    • 2015-12-09
                    • 1970-01-01
                    • 2018-04-30
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    相关资源
                    最近更新 更多