Getting the below error at the time of running java program in android studio.
Error:Execution failed for task \':app:preDebugAndroidTestBuild\'.
<
I found this very easy.
We will use update and use same version for all modules.
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'
}
build.gradle
, and use global variablesapp 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.
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.
build.gradle
- classpath 'com.android.tools.build:gradle:3.2.0'
(Track android.build.gradle release & this) buildToolVersion
(Track buildToolVersion release)compileSdkVersion
and targetSdkVersion
Track platform release Happy coding! :)