通常建立一個android項目後回出現兩個gradle:一個build.gradle(app),一個build.gradle(Project),顧名思義就是一個是用來配置整個工程的的一個是用來配置app的。android
1、gradle中dependencies 的區別:
下面英文就是對compile和classpath區別的解釋:app
I’m going to guess that you’re referencing compile and classpath
within the dependencies {} block. If that is so, those are dependency
Configurations.eclipse
A configuration is simply a named set of dependencies. The compile
configuration is created by the Java plugin. The classpath
configuration is commonly seen in the buildSrc {} block where one
needs to declare dependencies for the build.gradle, itself (for
plugins, perhaps).maven
classpath的做用:ide
buildscript itself needs something to run, use classpath單元測試
complie的做用:測試
your project needs something to run, use compilegradle
在Project中的gradle的dependencies 指添加依賴是使用classpath的,classpath通常是添加buildscript自己須要運行的東西,那麼buildscript是用來什麼呢?buildScript是用來加載gradle腳本自身須要使用的資源,能夠聲明的資源包括依賴項、第三方插件、maven倉庫地址等。
在app中的gradle中dependencies 中添加的使應用程序所須要的依賴包,也就是項目運行所須要的東西。ui
2、compile有哪幾種?
Compile
compile是對全部的build type以及favlors都會參與編譯而且打包到最終的apk文件中。spa
Provided
Provided是對全部的build type以及favlors只在編譯時使用,相似eclipse中的external-libs,只參與編譯,不打包到最終apk。
APK
只會打包到apk文件中,而不參與編譯,因此不能再代碼中直接調用jar中的類或方法,不然在編譯時會報錯
Test compile
Test compile 僅僅是針對單元測試代碼的編譯編譯以及最終打包測試apk時有效,而對正常的debug或者release apk包不起做用。
Debug compile
Debug compile 僅僅針對debug模式的編譯和最終的debug apk打包。
Release compile Release compile 僅僅針對Release 模式的編譯和最終的Release apk打包。