优化项目时,项目组件化实现下用通常方式来实现多渠道存在问题:

通用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即可自动改变成所选择的渠道

cd0db371a8f06ecd32369ff1d49b7ba5.png

如上

欢迎探讨

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐