android多渠道 依赖,在Android Library的Module中按渠道依赖

本文详细介绍了如何在Android项目中设置多渠道打包的问题。关键在于在library的build.gradle文件中将publishNonDefault设为true,并按用户指南定义依赖项。通过这种方式可以针对不同的市场配置不同的应用风味,实现灵活的多渠道构建。

Finally I found out how to do this, I will explain it here for others facing same problem:

The key part is to set publishNonDefault to true in library build.gradle, Then you must define dependencies as suggested by user guide.

The whole project would be like this:

Library build.gradle:

apply plugin: 'com.android.library'

android {

....

publishNonDefault true

productFlavors {

market1 {}

market2 {}

}

}

project build.gradle:

apply plugin: 'com.android.application'

android {

....

productFlavors {

market1 {}

market2 {}

}

}

dependencies {

....

market1Compile project(path: ':lib', configuration: 'market1Release')

market2Compile project(path: ':lib', configuration: 'market2Release')

}

Now you can select the app flavor and Build Variants panel and the library will be selected accordingly and all build and run will be done based on the selected flavor.

If you have multiple app module based on the library Android Studio will complain about Variant selection conflict, It's ok, just ignore it.

05165318_SJ3D.jpg

其他参考

https://stackoverflow.com/questions/24307596/how-can-i-add-flavors-in-a-module-with-android-studio

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值