由于构建工具,我的Gradle文件必须与Android Gradle 2.1.3和最新的Android Gradle版本兼容。最新的Android Gradle插件引入了 implementation 和 api 配置,并计划删除 compile 配置,我试图找到一种方法来编写脚本,它应该能够支持这两个版本。 我们的想法是使用
implementation
api
compile
def _api = api
而且在 dependencies 使用 _api 而不是 应用程序编程接口 .
dependencies
_api
应用程序编程接口
稍后,我们计划添加一些类似的代码;
if (oldVersion) _api = compile
我试过这个代码,但它是无效的代码。 你知道应该如何编码吗?
提前谢谢
符号:
dependencies { api "org.example:example:1.0" }
是真正的句法糖分
dependencies { add("api", "org.example:example:1.0") }
所以你可以通过定义 String 变量,其值取决于渐变版本。
String