android 公共组件,Android 组件化在公用Module里实现多渠道打包配置
优化项目时,项目组件化实现下用通常方式来实现多渠道存在问题:通用Module无法引用到主模块app下的渠道配置信息,需要另作配置,为此做个记录:主Module下配置渠道信息android {....buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'),
优化项目时,项目组件化实现下用通常方式来实现多渠道存在问题:
通用Module无法引用到主模块app下的渠道配置信息,需要另作配置,
为此做个记录:
主Module下配置渠道信息
android {
....
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}
//配置渠道
productFlavors {
test1 {...}
test2 {...}
test3 {...}
}
}
//这里自定义关键字来获取指定渠道来编译
configurations {
test1DebugApi
test2DebugApi
test3DebugApi
test1ReleaseApi
test2ReleaseApi
test3ReleaseApi
}
//配置的格式:自定义关键字 project(path: ':通用Module', configuration: '对应的渠道')
dependencies {
...
test1DebugApi project(path: ':libary', configuration: 'test1Debug')
test2DebugApi project(path: ':libary', configuration: 'test2Debug')
test3DebugApi project(path: ':libary', configuration: 'test3Debug')
test1ReleaseApi project(path: ':libary', configuration: 'test1Release')
test1ReleaseApi project(path: ':libary', configuration: 'test2Release')
test1ReleaseApi project(path: ':libary', configuration: 'test3Release')
}
子Module配置:
android {
....
buildTypes {
release {...}
debug {...}
}
//配置渠道
productFlavors {
publishNonDefault true//子Module里必须配置
test1 {...}
test2 {...}
test3 {...}
}
}
dependencies {
...
}
sync项目后,在Build Variants中选择不同渠道包子Module即可自动改变成所选择的渠道
如上
欢迎探讨
更多推荐
所有评论(0)