Search code examples
gradleintellij-ideaandroid-gradle-pluginandroid-build

How to import local *jar per gradle?


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!?

Solution

  • 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.