Android separate string values for release and debug builds

Viewed 17375

Every time i release my app i change all my url strings and some keys from testing to production. The way I do it is just comment out the testing strings before i release. Is there a better way to handle strings based on the build type ?

3 Answers

Well, you can use Gradle if needs to use for a few strings

buildTypes {
    release {
        resValue 'string', 'adUnitIdMain', '"production-id-value-should-be-here"'
        resValue 'string', 'adUnitIdList', '"production-id-value-should-be-here"'
        resValue 'string', 'adUnitIdDetail', '"production-id-value-should-be-here"'
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    debug {
        resValue 'string', 'adUnitIdMain', '"test-id-value-should-be-here"'
        resValue 'string', 'adUnitIdList', '"test-id-value-should-be-here"'
        resValue 'string', 'adUnitIdDetail', '"test-id-value-should-be-here"'
    }
}
Related