Android Project和app中兩個build.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打包。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM