Gradle Version ,
Android Plugin Version,
classpath 'com.android.tools.build:gradle:2.2.0-rc1',
buildToolsVersion"25.0.2"
apply plugin:'com.android.application'
這些配置到底都具體對應著什么,相互間有什么聯系,一直都很模糊。
最近在翻看Gradle for Android,大概了解了一點,先記錄一下。不對之處請狠狠指出!
1.Gradle Version
如果設置了Gradle Wrapper,一般都是gradle-wrapper.properties這個文件里面配置的版本號:distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
對應應該是gradle的語言版本。
對于wrapper書中有介紹:
The Gradle Wrapper provides a batch? file on Microsoft Windows and a shell script on other operating systems. When you run the script, the required version of Gradle is downloaded (if it is not present yet) and used automatically for the build. The idea behind this is that every developer or automated system that needs to build the app can just run the wrapper, which will then take care of the rest. This way, it is not required to manually install the correct version of Gradle on a developer machine or build server. Therefore, it is also recommended to add the wrapper? files to your version control system.
大意是不用手動去下載工程需要的gradle版本,wrapper會自動去下載該工程需要的版本。所以./gradlew? 這個指令 后面的w應該就是指的wrapper把。(比如$ gradlew assembleDebug等)
以及,gradle wrapper主要由 一個批處理文件,一個jar,一個配置文件gradle-wrapper.properties組成,書中有介紹就不多說了。。
2 Android Plugin Version,classpath'com.android.tools.build:gradle:2.2.0-rc1',
Android Plugin Version這個應該和classpath'com.android.tools.build:gradle:2.2.0-rc1', 這項配置是對應的。 安卓插件版本。
書中第一句話確實也說了,這個classpath 就是android build tools的 maven倉庫地址,android plugin也是來自于這個build tools. android plugin提供了構建和測試一個application的所有tasks,在module中,如果是application類型的module,就要在module級的build.gradle下 加入
applyplugin:'com.android.application',或者是library類型的module,就applyplugin:'com.android.library',
第二章對Android plugin有說明:
The Android plugin is written and maintained by the Android Tools team at Google, and provides all tasks needed to build, test, and package Android applications and libraries.
So,Android build tools == Android Plugin??
3.buildToolsVersion"25.0.2"
書中Page22:
這個build tools 就要與 Android build tools區分一下了,這個提供了一些 aapt,zipalign,dx等 命令行工具,可以通過sdk manager下載。
4.apply plugin:'com.android.application'
上面已經說過了,來自于....Android build tools.
So,大概梳理了一下,大概就是Android build tools(Android Plugin)的某些版本 對應Gradle的某些版本(具體對應關系可以百度),然后 build tools(buildToolsVersion)是在android plugin配置完成之后,在build file的android block下 配置的一個 構建工具版本。
接下來如果再看到這個錯誤,Plugin is too old 就應該知道了是Android build tools太老了,classpath'com.android.tools.build:gradle:2.2.0-rc1',改一下應該就ok了,知道原理就不用去百度了~~