在一个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的形式声明引用
以上,求详解
1, 3, and 4 are essentially the same, the difference is:
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.
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"