9

Android 构建指北 #12 根据 Variant 决定是否启用插件

 3 years ago
source link: https://www.v2ex.com/t/825425
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Android

Android 构建指北 #12 根据 Variant 决定是否启用插件

  2bab · 13 小时 9 分钟前 · 245 次点击

应该算是大家都会遇到的问题了,写了篇文章聊聊了怎么解决。

https://mp.weixin.qq.com/s/Zlm4PbqM0KlCxkd4xMvRIQ

4 条回复    2021-12-31 17:19:26 +08:00

zhouquanbest

zhouquanbest      7 小时 57 分钟前

这其实有点伪命题,应该是 plugin 决定需要给那些 variant 注册 task or 其他 action

但这点不符合绝大多数同学的直觉,所以最简单高效的还是通过命令名字判断,否则教育和维护成本太高了。

2bab

2bab      6 小时 5 分钟前

@zhouquanbest 确实不符合直觉,但按方案三来说这其实是 Gradle 的门槛不是这篇文章的门槛哈哈哈(需要同学有基本的 Task 相关知识)。命题还算正确的吧~ 禁用插件功能( Task ),粒度更细,同时也是禁用插件的一种方式,毕竟 Configuration Phrase 并没有耗时操作,如果禁掉后面所有的执行期操作基本也是等价于禁用插件了。如果从效果来说,比用命令名判断更安全、有效。我还是希望传播正确的思路~

john6lq

john6lq      6 小时 0 分钟前

没太看懂...想知道能解决什么具体问题吗?

2bab

2bab      5 小时 43 分钟前

@john6lq

> 在 Android 开发中使用过第三方 Gradle 插件的同学都应该碰到过这个问题:我只想在某一些 buildType 或者 flavor 中应用这个插件,但是找不到合适的办法。

具体的例子:
1. 比如我只想在 Release 的 buildType 引入 andresguard 插件的功能
2. 比如我不想在 LocalDebug 的 variant 上传 mapping file ( Firebase 插件的一个功能)

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK