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')
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With