4

I included a local *.jar file (library) as described here..

  1. Click File from the toolbar
  2. Project Structure
  3. Select Modules at the left panel
  4. Dependencies tab
  5. '+' → JARs or directories

Now, I committed the Android project to github and the previous setting of that local jar file seem to be missing.

Whenever colleagues checkout that project, they do not have the path to that other jar-file.

Questions:

  1. Where can I specify these steps from above in a gradle (or any other file) to have a link to that *.jar file?
  2. Another possibility would be a libsfolder in my app module. What would be the pros and cons compared to 1?
  3. Other possibility also by adding the jar to my git!?
Noam Silverstein
  • 819
  • 2
  • 12
  • 18

1 Answers1

5

I always prefer a simple approach like:

  1. Copy your JAR file to your module libs folder.

  2. Add the dependency in the build.gradle file

In build.gradle:

dependencies {
    // Dependency on local binaries
    implementation fileTree(dir: 'libs', include: ['*.jar'])

   //Alternatively, you can specify individual files as follows:
   //implementation files('libs/myJar.jar', 'libs/bar.jar')

   //..
}

It is not related to a particular procedure to follow, it works with different IDE (also in a CI environment), just all the code and the jars file are in the git repo and the build.gradle script is enough to build the project.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I already know how to do it 'libs' way, see 2. in questions section in the original post above. The question here is about the pros and cons compared to project setting way? – Noam Silverstein Jun 21 '19 at 10:04
  • I always prefer this way. It is not related to IDE used (it can also work in a CI environment) and it is not related to a procedure to follow. All the code and the jars are in the git repo, and the build.gradle script is enough to build the project. – Gabriele Mariotti Jun 21 '19 at 10:17
  • in app module gradle: `implementation fileTree(include: ['*.jar'], dir: 'libs')` lead to Unresolved reference: eid – Noam Silverstein Jun 21 '19 at 13:28