Android Studio 3.0 升级 配置修改详解

更新完Android Stuido 3.0 稳定版之后,打开项目会收到如下提醒


谷歌强烈建议我们更新Android Gradle Plugin 3.0 和 Gradle 4.1,所以我就习惯性的点击了Update。  


结果……导致了一系列的修改。


1、Flavor Dimensions 配置

我的项目中用了多渠道,3.0之前配置多渠道:productFlavors配置不同的渠道包,3.0 新增了flavorDimensions的配置 

编译的时候报错:

Error:All flavors must now belong to a named flavor dimension. Learn more athttps://d.android.com/r/tools/flavorDimensions-missing-error-message.html


打开后面的链接查看原因。

Plugin 3.0.0 includes a new dependency mechanism that automatically matches variants when consuming a library. This means an app's redDebug variant will consume a library's redDebug variant. To make this work, the plugin now requires that all flavors belong to a named flavor dimension —even if you intend to use only a single dimension. Otherwise, you will get the following build error:

Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
Android Plugin3.0包含了一种新的依赖机制:在使用library时会自动匹配variant(debug, release),就是说app的debug会自动匹配library的debug。同样如果使用flavor的时候,比如app的redDebug同样会自动匹配library的redDebug。虽然有这样的优势,但是在使用flavor时,必须定义flavor dimension,否则会提示错误。


To resolve this error, assign each flavor to a named dimension, as shown in the sample below. Because dependency matching is now taken care of by the plugin, you should name your flavor dimensions carefully. For example, if all your app and library modules use the foo dimension, you'll have less control over which flavors are matched by the plugin. 

// Specifies a flavor dimension.
flavorDimensions "color"

productFlavors {
     red {
      // Assigns this product flavor to the 'color' flavor dimension.
      // This step is optional if you are using only one dimension.
      dimension "color"
      ...
    }

    blue {
      dimension "color"
      ...
    }
}
现在使用flavor,必须像上面那样配置。


2、新的依赖配置

Gradle 3.4 推出了新的Java library plugin 配置:允许控制发布以编译和运行时类路径(用于模块间依赖)


通过下面一张图来说明下新的Java library plugin 配置关系:


1)绿色方块:使用者可以使用的依赖,比如:app配置library的依赖 
2)粉色方块:组件对library:编译时或者运行时 
3)蓝色:组件内部使用,注意这里是不用传递的,比如a依赖b,b依赖c, 但是a不能获取c的配置 
4)白色:配置集成自java plugin



  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值