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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50089436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:25:49  来源:igfitidea点击:

Error:Execution failed for task ':app:preDebugAndroidTestBuild' , when tried to run java program in android studio

javaandroid

提问by Kms

Getting the below error at the time of running java program in android studio.

在 android studio 中运行 java 程序时出现以下错误。

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

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

Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.htmlfor details.

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

Any solution please. ?

请任何解决方案。?

采纳答案by mahmoud zaher

thanks to @Ganesh Bhat and Chad Bingham

感谢@Ganesh Bhat 和 Chad Bingham

For those who still facing the problem, above answer did not help me in android studio 2.2 Preview.

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

This fixed my issue.

这解决了我的问题。

add this to your gradle file.

将此添加到您的 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

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

Android support library error after updating to 23.3.0

更新到 23.3.0 后 Android 支持库错误

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

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



update - if the previous answer doesn't work :

更新 - 如果之前的答案不起作用:

you should update the compileSdkVersionand appcompatto the latest update till now compileSdkVersion is 27 , also appcompat is 27.1.1 and 28.0.0-alpha1 is a pre-release version

你应该更新compileSdkVersionappcompat到最新的更新,直到现在 compileSdkVersion 是 27 ,appcompat 是 27.1.1 和 28.0.0-alpha1 是一个预发布版本

thus

因此

change

改变

compileSdkVersion 27

compileSdkVersion 27

the attached photo will help you

附上的照片会帮助你

and

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

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

to latest update

到最新更新

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

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

you can check the latest updates from this link :

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

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

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

回答by Nazmus Saadat

Use implementation 'com.android.support:appcompat-v7:27.1.1'instead of implementation 'com.android.support:appcompat-v7:26.1.0'and change compileSdkVersion 26 to 27

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

回答by Ashana.Hymanol

Add these lines within your app dependenciesbraces,

在您的应用程序依赖项大括号中添加这些行,

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

Latest is 27.1.1 upto this date.

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

回答by SHISHIR

Add This Code to the bottom of build.gradle at app level. It will work...

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

回答by Anandharaj R

AS configuration version:

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

回答by Mohammed mansoor

Add this to your app gradle file

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

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

回答by Hemn Hamza

Hello guys I had the same problem for solving this problem u need to change you appcompat in your app bulid gradle to

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

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

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

then it should ask you to instal it if u have'nt installed if still errore didnt solved change your sdkversions it will help alot because if u change the appcompact to 27.1.1 u need to change your sdkversion to 27 as well i suggest all of u to update your android studio and the sdk to the lastest

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

回答by Mohammed Fuzail

Well, I too faced the same problem here is how I fixed it

好吧,我也遇到了同样的问题,这就是我如何修复它

  • Goto app level Gradle file
  • 转到应用级 Gradle 文件

There you will find what are all the config's you have set up. In my case here

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

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 and

所以这里只需将 compileSdkVersion & targetSdkVersion 从 26 更改为 27 和

from dependencies change support 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 !!!

已修复!!!

回答by Ready Android

Error:

错误:

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.htmlfor details.

错误:任务 ':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

This is due to there is no dependency added to your App build.gradle or might be its an old version. So, add a dependency for annotation support.

这是因为您的 App build.gradle 没有添加依赖项,或者可能是旧版本。因此,添加注释支持的依赖项。

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

Here I have added annotation version 27.1.1 to solve your error if this is mismatched with different version then change it to the required version.

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