我正在为调用RESTful Web服务的代码编写测试。我需要使用不同的变量进行测试,分段和生产。例如,staging release url可以是'myapp.staging.com',而当我测试staging flavor时,它应该是'localhost / 27015'。生产风味也是如此。什么时候发布它应该是'myapp.production.com'。我如何实现这些风格,buildType组合?
答案 0 :(得分:2)
您可以使用BuildType和flavor来实现它。
如果您想为不同的组合使用不同的网址,则可以使用资源中的值。
使用flavor1,flavor2你有 4 Build Variants
您可以在资源中设置网址,例如在strings.xml
文件中
然后,您可以在这些文件夹中设置不同的文件,以达到您想要的效果。
src/flavor1/
src/flavor1Debug/
src/flavor1Release/
src/flavor2/
src/flavor2Debug/
src/flavor2Release/
您可以在applicationId
文件中设置所有其他值,例如build.gradle
。
答案 1 :(得分:1)
答案 2 :(得分:0)
以下是我们正在做的事情......这是我们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
}
}