1、Android配置打多个包
将下面的配置放在app的gradle的android节点下,与defaultConfig节点同等级。里面配置了多个版本.
android {
flavorDimensions "default"
productFlavors {
dev {
//这里是在 applicationId 中添加了一个后缀。所以『.』要加上
applicationIdSuffix ".dev"
buildConfigField "String", "AppEnvironment", "\"dev\"" //dev
buildConfigField "String", "AppUrl", "\"http://dev.xxxx-tms.xxxx.com/\""
buildConfigField "String", "AppBugly", "\"1234567\"" //腾讯Bugly
manifestPlaceholders = [
application_label: "TMS_Dev"]
}
qa {
//这里是在 applicationId 中添加了一个后缀。所以『.』要加上
applicationIdSuffix ".test"
buildConfigField "String", "AppEnvironment", "\"test\"" //test
buildConfigField "String", "AppUrl", "\"http://test.xxxx-tms.xxxx.com/\""
buildConfigField "String", "AppBugly", "\"1234567\"" //腾讯Bugly
manifestPlaceholders = [
application_label: "TMS_Test"
]
}
prod {
buildConfigField "String", "AppEnvironment", "\"release\"" //生产
buildConfigField "String", "AppUrl", "\"http://test.xxxx-tms.xxxx.com/\""
buildConfigField "String", "AppBugly", "\"1234567\"" //腾讯Bugly
manifestPlaceholders = [
application_label: "TMS"
]
}
}
}
将改变后的代码添加进去,并且将其中的包名改成自己的包名,就可以打多个包了。
2、Android使用配置的APP名称
//必须都写,否则报错
android:label="${application_label}"
tools:replace="android:label"
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/app_logo"
android:name=".AsuraApplication"
android:label="${application_label}"
android:roundIcon="@mipmap/app_logo"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:replace="android:label"
>
//省略...
</application>
3、Android使用配置AppUrl
import com.asura.android.tmspda.BuildConfig
var url = BuildConfig.AppUrl
网友评论