原文:http://www.javashuo.com/article/p-fwsrbbmk-mr.htmlhtml
The Android Studio build system is based on Gradle, and the Android plugin for Gradle adds several features that are specific to building Android apps.
Android Studio基於Gradle構建系統,爲了構建Android應用,Android gradle 插件添加了構建Android應用程序特有的幾項功能。java
build.gradle
文件中buildscript {
repositories {
/**Gradle 4.1 and higher include support for Google's Maven repo using the google() method. And you need to include this repo to download Android plugin 3.0.0 or higher.*/ jcenter() google() ... } dependencies { classpath 'com.android.tools.build:gradle:3.1.1' } } allprojects { repositories { jcenter() google() } }
buildscript定義了全局的相關屬性
repositories
定義倉庫:一個倉庫表明着依賴包的來源,例如jcenter倉庫dependencies
用來定義構建過程:僅僅須要定義默認的Android插件
,該插件能夠讓你執行相關Android的tasks,注意:不該該在該方法體內定義子模塊的依賴包。allprojects
用來定義各個模塊的默認屬性:不單單侷限於默認的配置,也能夠本身創造tasks在allprojects方法體內,這些tasks將會在全部模塊中可見。android
gradle/wrapper/gradle-wrapper.properties
文件中distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Android Studio升級爲3.1,Gradle 4.4,buildToolsVersion 27.0.3所帶來的問題
使用implementation或者api代替compile
nginx
dependencies { compile 'com.google.dagger:dagger:2.11' compile 'com.google.dagger:dagger-android:2.11' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' }
dependencies { implementation 'com.google.dagger:dagger:2.11' implementation 'com.google.dagger:dagger-android:2.11' debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' }
api和implementation的區別:
api:模塊的依賴對外公開,可被依賴包所引用(徹底等同於compile指令)
implementation:依賴只做用於當前的module
,將該模塊的依賴隱藏在內部,而不對外部公開(使用implementation指令的依賴不會傳遞)git
有一個module_A依賴於glide(module_A使用的是implementation 指令來依賴glide)github
implementation 'com.github.bumptech.glide:glide:3.7.0'
另外一個module_B,依賴於module_A:編程
implementation project(':module_A')
此時module_B裏邊不能引用glide,module_B要想引用glide,就在module_A使用的是api來引用glide
api
api 'com.github.bumptech.glide:glide:3.7.0'
用implementation指令編譯,Glide依賴對Module是module_B是不可見的
用api指令編譯,Glide依賴對Module是module_B是可見的 android-studio
建議:在Google IO 中提到了一個建議,依賴首先應該設置爲implementation的,若是沒有錯,那就用implementation,若是有錯,那麼使用api指令。`使用implementation會使編譯速度有所增快。`
將instrumentTest改成 androidTest
新版本Gradle對instrumentTest作了重命名ruby
舊版本 | 新版本 |
---|---|
instrumentTestCompile | androidTestCompile |
instrumentTest | androidTest |
項目裏使用了me.tatarka:gradle-retrolambda,
dependencies { classpath 'me.tatarka:gradle-retrolambda:3.2.5' }
對retrolambda進行了升級,解決了問題
dependencies { classpath 'me.tatarka:gradle-retrolambda:3.7.0' }
dependencies {
//classpath 'com.novoda:bintray-release:0.5.0' classpath 'com.novoda:bintray-release:0.8.0' }
升級com.novoda.bintray-release版本