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

后端 未结 14 1221
渐次进展
渐次进展 2021-02-13 03:03

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

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

<
相关标签:
14条回答
  • 2021-02-13 03:38

    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.html for details.

    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.

    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.

    0 讨论(0)
  • 2021-02-13 03:40

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

    • Goto app level Gradle file

    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

    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 !!!

    0 讨论(0)
  • 2021-02-13 03:41

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

    0 讨论(0)
  • 2021-02-13 03:41

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

    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")
                }
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-13 03:44

    Add these lines within your app dependencies braces,

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

    Latest is 27.1.1 upto this date.

    0 讨论(0)
  • 2021-02-13 03:44

    Try below change if it helps you

    com.android.support:appcompat-v7:26.1.0

    to

    com.android.support:appcompat-v7:27.1.1

    0 讨论(0)
提交回复
热议问题