Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Best practices for variables in Gradle build script

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.

like image 630
Gyroscope Avatar asked Mar 04 '14 11:03

Gyroscope


People also ask

Do we need to set environment variables for Gradle?

Environment variables are needed to customise the execution of the gradle tasks. Below is the working code in gradle 7.3.

What is the use of Buildscript in Gradle?

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.


1 Answers

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.

like image 115
craned Avatar answered Sep 19 '22 03:09

craned