2016年9月20日 星期二

Set the Vairable in the Gradle

defaultConfig {
        applicationId "com.apptask.kerryproperties"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 2
        versionName '0.3.3'
        buildConfigField 'boolean', 'SHOW_LOG', 'false'
        buildConfigField 'boolean', 'SHOW_ERROR', 'true'
    }
    productFlavors {
        uat {
            buildConfigField 'boolean', 'SHOW_LOG', 'true'
            buildConfigField 'boolean', 'SHOW_ERROR', 'true'
            buildConfigField "String", "BASE_URL", "\"http://uat.services.mrm.hk/api/index.php?\""
        }
        production {
            buildConfigField 'boolean', 'SHOW_LOG', 'false'
            buildConfigField 'boolean', 'SHOW_ERROR', 'true'
            buildConfigField "String", "BASE_URL", "\"http://uat.services.mrm.hk/api/index.php?\""
        }
    }

than ,you can use like this
private static final String BASE_URL = BuildConfig.BASE_URL;