標籤:

Android Studio 3.0工具升級

1. Gradle 4.0兼容性

之前使用Gradle 3.x編譯時,經常有這個警告報告:

The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.

很討厭並且還不知道問題是什麼。

終於盼到Gradle 4.0,編譯Android代碼,這下不讓編譯了。

> Failed to notify project evaluation listener. > com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V > Could not get unknown property assembleRelease for project :xxx of type org.gradle.api.Project.

根據Gradle wrapper · Issue #10236 · flutter/flutter說法,應該是Android gradle plugin版本太舊的問題。目前我們使用的是com.android.tools.build:gradle:2.2.3(2017.6.9),這也算太舊。。。

解決辦法:

修改頂級build.gradle中com.android.tools.build:gradle的版本到>=2.3.0,目前穩定版是2.3.3。可以在Index of /repositories/jcenter/com/android/tools/build/gradle查詢下最新版本。

classpath com.android.tools.build:gradle:2.3.3

如果單純修改com.android.tools.build:gradle,遇到SDK Build Tools版本太低會報:

The SDK Build Tools revision (23.0.3) is too low for project :xxx. Minimum required is 25.0.0

所以修改子工程build.gradle中

buildToolsVersion 23.0.3

buildToolsVersion 25.0.3

又有新問題:

The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.

估計過一段時間還得升級com.android.tools.build:gradle版本。

推薦閱讀:

國內有Android技術團隊在使用facebook的buck進行代碼構建嗎?
Bugly多渠道熱更新解決方案
如何在做網上自動化賺錢項目?
2016年讀過的Android好書推薦

TAG:Gradle | Android |