前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >在Android Library的Module中按渠道依赖

在Android Library的Module中按渠道依赖

作者头像
全栈程序员站长
发布于 2021-06-21 08:27:45
发布于 2021-06-21 08:27:45
1.2K00
代码可运行
举报
运行总次数:0
代码可运行

2019独角兽企业重金招聘Python工程师标准>>>

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:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
apply plugin: 'com.android.library'

android {        
    ....
    publishNonDefault true
    productFlavors {
        market1 {}
        market2 {}
    }
}

project build.gradle:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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.

其他参考

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

转载于:https://my.oschina.net/sfshine/blog/2870349

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101336.html原文链接:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档