Just wondering what the best practice is for using variables in Gradle build scripts. More specifically, I have set minSdkVersion and targetSdkVersion in my buildscript and Android Studio presents the following message when looking at my apps manifest.
This minSdkVersion value (14) is not used; it is always overridden by the value specified in the Gradle build script(14)
This is a snippet from my build script:
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
Should I still keep the declaration in the manifest? or should I remove any variables I set in the build script from the app's manifest?
Many thanks.
Environment variables are needed to customise the execution of the gradle tasks. Below is the working code in gradle 7.3.
buildscript: This block is used to configure the repositories and dependencies for Gradle. dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project.
I had this same question. Maybe you have found the answer at this point, but some searching finally led me to this website.
It seems to explain all the Gradle
basics really well. For the answer to your specific question, look for Manifest Entries
under Basic Build Customization
. Near as I can tell, it works just fine to define minSdkVersion
in the build script or in the AndroidManifest.
As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code.
I probably didn't explain it the best, but that website does a pretty good job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With