Android开发也挺长时间了,从开始就使用的AndroidStudio开发,但是说下来其实自己对AS(AndroidStudio简称)还真的是不了解不深入、好吧,其实我只知道AS是一个相当强大的工具,我要学习的还有很多。
  言归正传,这段时间在学习RtroLambda和ButterKnife的使用,我发现他们的导入在Project的build.gradle中引入的而不是在app的build.gradle中,这让我觉得有点郁闷,因为我才发现不太知道这两个gradle的区别,下面来总结一下。

  一般创建一个android项目后回出现两个gradle:一个build.gradle(app),一个build.gradle(Project),顾名思义就是一个是用来配置整个工程的的一个是用来配置app的。

Android Project和app中两个build.gradle配置的区别_第1张图片

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

更多相关文章

  1. android Dependencies ,Private Libraries ,Referenced Libraries
  2. Android Layout的layout_height等属性为什么有时会不起作用?
  3. Android模拟器与真机的9个区别
  4. Android ART虚拟机和Dalvik虚拟机区别
  5. [android] Serializable 和 Parcelable 区别
  6. App测试中ios和Android的区别
  7. android 两个应用之间的通信与调用
  8. Android与J2ME区别之我见(3)

随机推荐

  1. ANDROID NDK文档系列--(二)Installation Gu
  2. 手动操作Android数据库
  3. Android(安卓)蓝牙自动配对连接
  4. Android(安卓)Studio AIDL进行IPC通信的
  5. Android(安卓)导航条效果实现(三) ViewPage
  6. android > WiFi > 扫描附近WIFI
  7. Android之数据库操作
  8. Android入门:Button
  9. 2013.12.04 (5)——— android SlidingMenu
  10. Android(安卓)Camera2 API 学习