Android Project和app中兩個build.gradle配置的區別

來源:互聯網
上載者:User

標籤:soft   倉庫   app   eth   配置   ext   dsr   分享   技術分享   

   Android 開發也挺長時間了,從開始就使用的AndroidStudio開發,但是說下來其實自己對AS(AndroidStudio簡稱)還真的是不瞭解不深入、好吧,其實我只知道AS是一個相當強大的工具,我要學習的還有很多。 
  言歸正傳,這段時間在學習RtroLambda和ButterKnife的使用,我發現他們的匯入在Project的build.gradle中引入的而不是在app的build.gradle中,這讓我覺得有點鬱悶,因為我才發現不太知道這兩個gradle的區別,下面來總結一下。

  一般建立一個android項目後回出現兩個gradle:一個build.gradle(app),一個build.gradle(Project),顧名思義就是一個是用來配置整個工程的的一個是用來配置app的。

 

一、gradle中dependencies 的區別:

下面英文就是對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打包。

 

Android Project和app中兩個build.gradle配置的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.