[英]Using Different Sources for Testing and Release Android Studio
I am writing tests to code that make calls to a RESTful web service.我正在为调用 RESTful Web 服务的代码编写测试。 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'.
例如,登台发布 url 可以是“myapp.staging.com”,而当我测试登台风格时,它应该是“localhost/27015”。 Same goes for the production flavor.
生产风味也是如此。 When it is the release it should be 'myapp.production.com'.
当它发布时,它应该是“myapp.production.com”。 How do I achieve these flavor, buildType combinations?
我如何实现这些风味、构建类型组合?
You can use the BuildType and the flavor to achieve it.您可以使用 BuildType 和风味来实现它。
If you want different url for the different combination you can use a values inside your resources.如果您想要不同组合的不同 url,您可以在资源中使用值。
Using flavor1, flavor2 you have 4 Build Variants .使用 flavor1, flavor2 你有4 Build Variants 。
You can set the url inside the a resource, for example in the strings.xml
file.您可以在资源中设置 url,例如在
strings.xml
文件中。
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.您可以在
build.gradle
文件中设置所有其他值,例如applicationId
。
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.