I am writing tests to code that make calls to a RESTful web service. I need to use different variables for testing, staging and production. For an example staging release url can be 'myapp.staging.com' whereas when I test the staging flavor it should be 'localhost/27015'. Same goes for the production flavor. When it is the release it should be 'myapp.production.com'. How do I achieve these flavor, buildType combinations?
You can use the BuildType and the flavor to achieve it.
If you want different url for the different combination you can use a values inside your resources.
Using flavor1, flavor2 you have 4 Build Variants .
You can set the url inside the a resource, for example in the strings.xml
file.
Then you can set different files in these folder to achieve what you want.
src/flavor1/
src/flavor1Debug/
src/flavor1Release/
src/flavor2/
src/flavor2Debug/
src/flavor2Release/
You can set all the other values, for example the applicationId
, in the build.gradle
file.
Yeah it's possible using productFlavours within your gradle file, so the each build variant would have it's own
Here's what we are Doing... This is our build File of our App.
defaultConfig {
applicationId 'com.XXXX.XXXXfyd'
minSdkVersion 17
targetSdkVersion 23
versionCode 55
versionName "1.0.0"
multiDexEnabled true
buildConfigField "boolean", "OTP_ENABLED", "false";
buildConfigField "boolean", "MINT_API_ENABLED", "false";
buildConfigField "String", "MINT_API_KEY", "\"XXCVVF\"";
resValue "string", "app_name", "XXXXfyd Debug"
resValue "string", "account_name", "XXXXfyd Debug"
resValue "string", "account_type", "com.XXXX.XXXXfyd.debug"
resValue "string", "account_authority", "com.mind.eventifyd.debug.provider"
buildConfigField "String", "ACCOUNT_NAME", "\"XXXXfyd Debug\""
buildConfigField "String", "ACCOUNT_TYPE", "\"com.XXXX.XXXXfyd.debug\""
buildConfigField "String", "ACCOUNT_AUTHORITY", "\"com.XXXX.XXXXfyd.debug.provider\""
buildConfigField "String", "XXXXXFYD_XXXXX_URI", "\"http://XXX.XXX.XX.XX\"";
buildConfigField "String", "XXXXFYD_XXXX_URI", "\"XXXX//XXXXX@XXX.XXX.XX.XX:XXXXX\""
}
buildTypes {
release {
/* zipAlignEnabled true
minifyEnabled true*/
shrinkResources false
debuggable false
/* proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'*/
signingConfig signingConfigs.release
versionNameSuffix "-build." + getDate()
resValue "string", "app_name", "XXXXXfyd"
buildConfigField "boolean", "OTP_ENABLED", "false";
buildConfigField "boolean", "MINT_API_ENABLED", "true";
buildConfigField "String", "MINT_API_KEY", "\"efrtgyhu\"";
resValue "string", "account_name", "XXXXXfyd"
resValue "string", "account_type", "com.XXXX.XXXXfyd"
resValue "string", "account_authority", "com.XXXX.XXXXfyd.provider"
buildConfigField "String", "ACCOUNT_NAME", "\"XXXXifyd\""
buildConfigField "String", "ACCOUNT_TYPE", "\"com.XXXX.XXXXifyd\""
buildConfigField "String", "ACCOUNT_AUTHORITY", "\"com.XXXX.XXXXfyd.provider\""
buildConfigField "String", "XXXFYD_XXXX_URI", "\"https://com.XXXX.XXXXfyd.XXXXXes.com\"";
buildConfigField "String", XXXXXFYD_XXXX_URI", "\"XXXX://XXXXX@XXXXXfyd.XXXXerXXXXs.com:XXXX\""
}
debug {
/* zipAlignEnabled true
minifyEnabled false*/
debuggable true
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
versionNameSuffix "-debug-build." + getDate()
}
}
productFlavors {
dev {
minSdkVersion 19
}
prod {
minSdkVersion 17
}
}
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.