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"
}

就直接解決這個問題。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章