简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM