作者:比熊--悉尼 | 来源:互联网 | 2023-10-12 13:23
背景
我有一个需求,要求是同一份代码要打两个包出来,只不过包名、logo、名称、签名、部分代码不一样,我是这样做的。
第一步
app的build.gradle中
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 30
versionCode 5
versionName "1.0.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
flavorDimensions "default"
}
signingConfigs {
debug {
storeFile file(KEY_PATH)
storePassword KEY_PASS
keyAlias ALIAS_NAME
keyPassword ALIAS_PASS
}
release {
storeFile file(KEY_PATH)
storePassword KEY_PASS
keyAlias ALIAS_NAME
keyPassword ALIAS_PASS
}
debugxiamen {
keyAlias 'xxxx'
keyPassword 'xxx'
storeFile file('../doc/xxx.jks')
storePassword 'xxx'
}
releasexiamen {
keyAlias 'xxxx'
keyPassword 'xxx'
storeFile file('../doc/xxx.jks')
storePassword 'xxx'
}
}
productFlavors {
hengqin {
applicationId "com.ly.checkticket4hengqin"
}
xiamen {
applicationId "com.ly.traffic.transport"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
productFlavors.hengqin.signingConfig signingConfigs.release
productFlavors.xiamen.signingConfig signingConfigs.releasexiamen
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
dataBinding {
enabled = true
}
}
签名配置
第二步
配置不同的logo、appname
第三步
代码里抹平渠道区分:
when(BuildConfig.FLAVOR){
"xiamen"->{}
"hengqin"->{}
}
第四步
打包
本文地址:https://blog.csdn.net/u012346890/article/details/112536211