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

后端 未结 14 1268
渐次进展
渐次进展 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: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! :)

提交回复
热议问题