Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between compile vs compile tree vs compile Files?

I was trying to integrate my project in android studio. but i am little confused when adding dependencies. I don't know which one is works good.I have tried Compile fileTree and compile files.Its not working for me . I found some methods.can any one tell me which one is appropriate for adding library (jar file only like admob).

            compile fileTree(dir: 'libs', include: '*.jar')
         compile 'com.android.support:appcompat-v7:+'
       compile project(":libraries:libraryname")
         compile files('libs/libraryname.jar')
like image 610
NightCrawler Avatar asked Dec 02 '13 16:12

NightCrawler


People also ask

What is difference between compile and compileOnly Gradle?

The compileOnly configuration is used to itemize a dependency that you need to compile your code, same as compile above. The difference is that packages your java code use from a compileOnly dependency will not be listed as Import-Package manifest entries.

What is compile and Testcompile in Gradle?

Compile − The dependencies required to compile the production source of the project. Runtime − The dependencies required by the production classes at runtime. By default, it also includes the compile time dependencies. Test Compile − The dependencies required to compile the test source of the project.

What is compile in build Gradle?

compile specifies an external dependency for the project you are building. compile requires group, name, and version. These can either be broken out or specified using the short form "group:name:version". see Gradle Dependency Management Basics.

What is compile only Gradle?

compileOnly: when we don't need any dependency at runtime, since compileOnly dependency won't become the part of the final build. we will get a smaller build size. runtimeOnly: when we want to change or swap the behaviour of the library at runtime (in final build).


1 Answers

can any one tell me which one is appropriate for adding library (jar file only like admob).

If the library is available as an artifact in a Maven or Ivy repository, like Maven Central, add the repository to your repositories block (e.g., mavenCentral()) and then use compile 'com.android.support:appcompat-v7:+', replacing the quoted string with the one that identifies the artifact that you want.

If the library is not available as an artifact, put the JAR in the appropriate directory (e.g., libs/ at the project level) and use compile fileTree(dir: 'libs', include: '*.jar').

compile project(":libraries:libraryname") is for sub-projects, which you probably do not have.

compile files('libs/libraryname.jar') works, but compile fileTree(dir: 'libs', include: '*.jar') is more flexible, as you do not have to change your build.gradle file for every JAR.

like image 166
CommonsWare Avatar answered Sep 22 '22 00:09

CommonsWare