安卓開發經驗——Android Studio的project中兩個build.gradle配置的區別

一般創建一個android項目後回出現兩個gradle:

  • build.gradle(Project):用來配置整個工程的
  • build.gradle(app):一個是用來配置app的

對compile和classpath區別的解釋:

I’m going to guess that you’re referencing compile and classpath
within the dependencies {} block. If that is so, those are dependency
Configurations.

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).

classpath的作用:

buildscript itself needs something to run, use classpath

complie的作用:

your project needs something to run, use compile

在Project中的gradle的dependencies指添加依賴是使用classpath的,classpath一般是添加buildscript本身需要運行的東西,那麼buildscript是用來什麼呢?buildScript是用來加載gradle腳本自身需要使用的資源,可以聲明的資源包括依賴項、第三方插件、maven倉庫地址等。

在app中的gradle中dependencies中添加的使應用程序所需要的依賴包,也就是項目運行所需要的東西。

compile有哪幾種?

Compile

compile是對所有的build type以及favlors都會參與編譯並且打包到最終的apk文件中。

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打包。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章