android tutorial - Use gradle properties in Android | Developer android - android app development - android studio - android app developement



Use gradle.properties for central versionnumber/buildconfigurations

You can define central config info's in

or do it with root gradle.properties file

the project structure

root
  +- module1/
  |     build.gradle
  +- module2/
  |     build.gradle
  +- build.gradle
  +- gradle.properties
click below button to copy code from our android learning website - android tutorial - team
  • global setting for all submodules in gradle.properties
# used for manifest
# todo increment for every release
appVersionCode=19
appVersionName=0.5.2.160726

# android tools settings
appCompileSdkVersion=23
appBuildToolsVersion=23.0.2
click below button to copy code from our android learning website - android tutorial - team

usage in a submodule

apply plugin: 'com.android.application'
android {
    // appXXX are defined in gradle.properties
    compileSdkVersion = Integer.valueOf(appCompileSdkVersion)
    buildToolsVersion = appBuildToolsVersion

    defaultConfig {
        // appXXX are defined in gradle.properties
        versionCode = Long.valueOf(appVersionCode)
        versionName = appVersionName
    }
}

dependencies {
    ...
}
click below button to copy code from our android learning website - android tutorial - team

Note: If you want to publish your app in the F-Droid app store you have to use magic numbers in the gradle file because else f-droid robot cannot read current versionnumner to detect/verify version changes.


Related Searches to Use gradle properties in Android