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

后端 未结 14 1254
渐次进展
渐次进展 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:24

    its important to take a look at this too, in your gradle

    targetSdkVersion 27
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    
    0 讨论(0)
  • 2021-02-13 03:28

    AS configuration version:

    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'**
    
    0 讨论(0)
  • 2021-02-13 03:28

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

    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

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

    I found this very easy.

    We will use update and use same version for all modules.

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

    some library/module 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...
    }
    

    The solution is to make your versions same as in all modules. So that you don't have conflicts.

    Tips for future

    I felt when I have updated versions of everything- gradle, sdks, libraries etc. then I face less errors. Because developers are working hard to make it easy development on Android Studio.

    Always have **latest but stable versions** Unstable versions are alpha, beta and rc, ignore them in developing.

    I have updated all below in my projects, and feel flawless coding.

    • 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)

    Happy coding! :)

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

    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

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

    thanks to @Ganesh Bhat and Chad Bingham

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

    This fixed my issue.

    add this to your gradle file.

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

    Reference: 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


    update - if the previous answer doesn't work :

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

    thus

    change

    compileSdkVersion 27

    and

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

    to latest update

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

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