Android studio 3.0 版本的出现的bug的总结

第一个问题:android-apt plugin is incompatible with future version of Android Gradle plugin. use 'annotationPro


Warning:android-apt plugin is incompatible with future version of Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead.

原因:更新Android studio 原来项目出现问题。 
分析: 尤其是采用butterknife工具的,采用新的Android Studio都会出现这样的问题,本人根据提示最后猜测原因可能是Android studio更新,然后gradle更新了,这样的话可能使原来的android-apt 工具跟不上节奏了,所以让采用annotationProcessor工具。 
解决: 把project下的build.gradle 当中的依赖 
buildscript { 
repositories { 
mavenCentral() 

dependencies { 
classpath ‘com.android.tools.build:gradle:2.4.0-alpha7’ 
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ 


修改成如下: 
buildscript { 
repositories { 
mavenCentral() 

dependencies { 
classpath ‘com.android.tools.build:gradle:2.4.0-alpha7’ 


然后再把module下的build.gradle : 
dependencies { 
compile project(‘:roadvance-sdk’)

compile ‘com.google.dagger:dagger:2.10’ 
apt ‘com.google.dagger:dagger-compiler:2.10’

compile ‘com.android.support:appcompat-v7:25.3.1’

compile ‘com.jakewharton:butterknife:8.5.1’ 
apt ‘com.jakewharton:butterknife-compiler:8.5.1’


修改如下: 
dependencies { 
compile project(‘:roadvance-sdk’)

compile ‘com.google.dagger:dagger:2.10’ 
annotationProcessor ‘com.google.dagger:dagger-compiler:2.10’

compile ‘com.android.support:appcompat-v7:25.3.1’

compile ‘com.jakewharton:butterknife:8.5.1’ 
annotationProcessor ‘com.jakewharton:butterknife-compiler:8.5.1’ 

再把 apply plugin: ‘com.neenbedankt.android-apt ’ 这个引用给删除。 
重新reBuild的一下

第二个问题:解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com

这个问题是Android studio升级到3.0之后,运行的时候会提示gradle要升级到3.5版本才能编译。于是我把我的gradle升级到了

 gradle-4.1-milestone-1 版本,是2017年7月份最新版本了。
于是我把主程序的build.gradle中的gradle版本改成了这个,具体指定哪个版本我也不知道,于是就写了个3.0+
 dependencies {
        classpath 'com.android.tools.build:gradle:3.0+' 
}
然后再次编译,又发现了毒。
提示:Error:All flavors must now belong to a named flavor dimension.Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html 
这个一个错误,意思是:所有的flavors都必须属于同一个风格。
=。=懵逼
去翻墙看了它提供的地址才知道:
 Plugin 3.0.0 includes a new dependency mechanism that automatically matches variants when consuming a library. This means an app's debug variant automatically consumes a library's debug variant, and so on. It also works when using flavors—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:
[cpp]  view plain  copy
  1. Error:All flavors must now belong to a named flavor dimension.  
  2. The flavor 'flavor_name' is not assigned to a 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. 
[cpp]  view plain  copy
  1. // Specifies a flavor dimension.  
  2. flavorDimensions "color"  
  3.   
  4. productFlavors {  
  5.      red {  
  6.       // Assigns this product flavor to the 'color' flavor dimension.  
  7.       // This step is optional if you are using only one dimension.  
  8.       dimension "color"  
  9.       ...  
  10.     }  
  11.   
  12.     blue {  
  13.       dimension "color"  
  14.       ...  
  15.     }  
  16. }  

大致是说,Plugin 3.0.0之后有一种自动匹配消耗库的机制,便于debug variant 自动消耗一个库,然后就是必须要所有的flavor 都属于同一个维度。
为了避免flavor 不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。
= 。=还是懵逼。说一堆依然不是很理解。
但是我们从中已经知道解决方案了:
在主app的build.gradle里面的
 defaultConfig {
 targetSdkVersion:***
minSdkVersion :***
versionCode:***
 versionName :***
//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
flavorDimensions "versionCode"
}

就直接解决这个问题。




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值