Android Studio3.0的正式版上線,給我們的開發又帶來了更多的新特性,也方便了許多,看着大家都在升級,我也迫不及待的把我的Studio進行一下改革,話說我也中間隔了幾個小版本一直沒有升級處理,下面我就給大家說一下我遇到的幾個小坑:
首先我在官網下載了最新的安裝包,下載安裝完畢都很順利,但是在運行編譯的時候遇到了小插曲:
1.Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
意思是:所有的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:
Android Plugin3.0的依賴機制:在使用library時會自動匹配variant(debug, release),就是說app的debug會自動匹配library的debug,相信大多數人也像我一樣,當library多了,不會手動選擇每個Library的variant。現在好了,它會自動匹配了。同樣如果使用flavor的時候,比如app的redDebug同樣會自動匹配library的readDebug。雖然有這樣的優勢,但是在使用flavor時,必須定義flavor dimension;
defaultConfig { ... versionName "1.0.0" flavorDimensions "versionCode" ... }
只需在gradle中配置defaultConfig同步一下就好;
同步完之後又遇到了第二個坑:
2.Warning:The `android.dexOptions.incremental` property is deprecated and it has
原來在Android開發過程中突破的方法數的限制,就在build.gralde中做了解決操作,其中有個如下的配置
dexOptions { preDexLibraries false jumboMode true javaMaxHeapSize "2g" incremental false }
現在android studio在不斷優化,更新之後貌似不需要再特意配置了,直接將dexOptions刪除即可。
3.Annotation processors must be explicitly declared now.
我在studio中用到了butterknife:7.0.1註解,沒想到在編譯的時候報錯,
只需配置:
defaultConfig {
...
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}
經歷了三個小坑之後,我的項目才正式在3.0上運行起來,Studio的不斷更新升級,配置也越來越高,替代了原有需要手動升級的配置,插件或者jar包,都需要我們重新進行學習,代碼再次敲起來。。。