下載Android Studio 3.0,并安裝噪裕,不做細講
之后打開項目提示讓更新gradle到4.1(這里指的是gradle/wrapper/gradle-wrapper.properties中的版本)
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
同時,將根目錄中的build.gradle中的gradle更新到了3.0.0郑什,原來是2.3.1
classpath'com.android.tools.build:gradle:3.0.0'
之后就是漫長的等待,然后就報錯了
Error:Cannotchoose between the following configurations of project :lp_messaging_sdk:
- debugApiElements
- debugRuntimeElements
- releaseApiElements
- releaseRuntimeElements
上網(wǎng)搜索了一下解決方案尊搬,在stackoverflow 上看到一個解決方案
就是compile project(path: ':lp_messaging_sdk', configuration: 'default')
這個解決方案慎用,我用了之后導(dǎo)致出現(xiàn)了其他的意想不到的bug(依賴庫中的jar包中的API不能使用了绵咱,這個問題研究了好久瓢颅,最后把configuration: 'default'刪除掉才好了恩尾,還是自己對gradle不夠了解)
實際上面那個問題是android-apt導(dǎo)致的,把他替換成annotationProcessor就可以了惜索,看來stackoverflow上的解決方案也有坑啊特笋,而且這個解決方案還被很多人采納了。巾兆。猎物。。
在去掉了android-apt,并替換apt為annotationProcessor后角塑,重新編譯蔫磨,接著問題又來了:
Error:The specified Android SDK Build Tools version (25.0.0) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.0.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.0'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
這個問題還是比較好解決的,他已經(jīng)給出了解決方案圃伶,就是這句話:To suppress this warning, remove "buildToolsVersion '25.0.0'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.意思就是堤如,移除掉你的buildToolsVersion,因為新的gradle有自己默認的buildTools。
在刪除了? buildToolsVersion '25.0.0'? 之后再次編譯窒朋,錯誤又來了:
Error:Failed to resolve: com.android.support:multidex:1.0.2
Add Google Maven repository and sync project
這個也好解決Add Google Maven repository and sync project搀罢,這個就不用翻譯了吧,在根目錄對應(yīng)的build.gradle中加入google()侥猩。
repositories {
google()
jcenter()
mavenCentral()
}
再次編譯之后竟然好了榔至,小項目上的問題果然少,在我的另一個大項目上還出現(xiàn)了一個問題:
Failed?to?transform?file?'xxx.aar'?to?match?attributes?{artifactType=android-exploded-aar}?using?transform?ExtractAarTransform
這個問題也折騰了挺長時間的欺劳,實際上就是你的項目中有bug唧取,導(dǎo)致你的那個想要的aar沒有生成,你可能想我之前沒bug呀划提,這也沒辦法枫弟,切換的時候會生成一些莫名其妙的bug。但是有bug你就提示bug吧鹏往,提示上面的問題就是google的不對了淡诗。好在在網(wǎng)上找到了2種解決方案,一種是把gradle版本降下去伊履,這個雖然可以解決問題袜漩,但我不提倡,不能回避問題嘛湾碎。第二種方案是清除緩存文件,將C:\Users\\.gradle\caches\transforms-1刪除奠货,重新編譯項目介褥,你的bug就暴露出來了,但是只是一次,你再編譯又出現(xiàn)上面的錯誤提示了柔滔。所以溢陪,要先將暴露出來的bug解決掉了,(我開始就是以為不是bug呢睛廊,結(jié)果再次編譯就不報哪個bug了形真,然后就陷入了死循環(huán))。解決掉bug后再次編譯還可能會出現(xiàn)上面錯誤提示超全,那就是還有bug唄咆霜,再清緩存,再編譯嘶朱,再解決bug蛾坯,直到編譯通過。
上面的那個bug的體現(xiàn)形式不止那一種疏遏,還有可能是:
Failed to transform file 'xxx.jar' to match attributes {artifactType=android-classes} using transform JarTransform
就是jar包找不到嘛脉课,解決方案和上面一樣。
到此财异,就踩完坑了倘零。去體驗一下Android Studio3.0的一些新工具吧