android - gradle中compile,provided,compile files,compile project有何区别?
怪我咯
怪我咯 2017-04-17 14:54:18
0
3
645

在一个Android项目的build.gradle中,dependencies闭包中有以下四种形式的声明:

compile 'com.android.support:appcompat-v7:22.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
compile files('libs/picasso-2.4.0.jar')
compile project(':androidPullToRefresh')

我想彻底弄清compile、provided、compile files、compile project四者的区别。
我的理解:
compile所指编译内容可以是本地的,也可以是远程(jCenter)中的。如果是本地的包,最好以aar形式给出

provided 不懂

compile files编译的是jar包

compile project编译的内容必须包含多有java代码、xml布局文件、AndroidManifest等,而且还要在项目的setting.gradle中用include的形式声明引用

以上,求详解

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
刘奇

1, 3, and 4 are essentially the same, the difference is:

1 是从repository(默认是jCenter())里下载一个依赖包进行编译并打包
3 是从本地的libs目录下寻找picasso-2.4.0.jar这个文件进行编译并打包。类似的命令有`compile fileTree(dir: 'libs', include: '*.jar')`——将libs目录下所有jar文件进行编译并打包。
4 是将另一个module(等同eclipse中的library)进行编译并打包

As for provided, it is provided for commands that only compile but do not package scenarios. That is, I have a dependency on a certain jar file when compiling, but when I finally package the apk file, I don't want to put this jar file in it, so I can use this command. At present, I only know of a plug-in scenario that requires this command. If you don’t understand it, you can leave it alone.

Ty80

Just like @ediblefreshwaterfish said.
compile file, compile project, and compile fileTree can all be regarded as subcommands of compile. The classes and resources inside will be packaged into the App you use, while provided will not, but you still need to provide them at runtime. .

左手右手慢动作

Recommended to take a look at "gradle for android"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template