同一部手机不能存在两个applicationId相同的APP,所以为需要为APP配置不同的applicationId
一个小坑: 【Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]】在AndroidManifest.xml文件中,provider中的android:authorities的值必须是唯一的。多个项目引用同一个类库(Module),就无法同时安装了,因为android:authorities的值是相同的。
flavorDimensions "version"
productFlavors {
MainNet {
dimension "version"
buildConfigField "String", "net_type", "\"MainNet\""
applicationIdSuffix ".main"
versionNameSuffix "-main"
}
TestNet {
dimension "version"
buildConfigField "String", "net_type", "\"TestNet\""
applicationIdSuffix ".test"
versionNameSuffix "-test"
}
RegTest {
dimension "version"
buildConfigField "String", "net_type", "\"RegTest\""
applicationIdSuffix ".reg"
versionNameSuffix "-reg"
}
}
为不同版本定制不同的App名称
// AndroidManifest.xml
<application
android:name=".activities.base.MyApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@drawable/app_icon"
android:label="${app_name}" // 清单文件占位符
tools:replace="label"
android:requestLegacyExternalStorage="true"
android:roundIcon="@drawable/app_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="q">
// build.gradle
productFlavors {
MainNet {
buildConfigField "String", "net_type", "\"MainNet\""
applicationId "com.bixin.wallet.mainnet"
manifestPlaceholders = [app_name: "@string/app_name"]
}
TestNet {
buildConfigField "String", "net_type", "\"TestNet\""
applicationId "com.bixin.wallet.testnet"
manifestPlaceholders = [app_name: "@string/testnet"]
}
RegTest {
buildConfigField "String", "net_type", "\"RegTest\""
// applicationId "com.bixin.wallet.regnet"
manifestPlaceholders = [app_name: "@string/regnet"]
}
}