2

I am trying to create, import and use a jar file in this project. I found multiple topics that explain the steps needed to import the file but none of them worked for me. I created a very simpe library and exported it as a jar file:

public class Simple {
    public static int add(int a, int b){
        return a+b;
    }
}

In Android Studio I created a libs folder and added the .jar file, right click, add as library and then tried to use Simple.add(1, 2); without success, the class is not recognized.

In the extensions folder I tried to created a new module and then import my .jar file in there. After the import Simple.add was also unrecognized in the project.

How should I optimally add a library in such a project?

user68678
  • 21
  • 2

2 Answers2

0

In android studio, you have to add libraries in build.gradle file

In gradle file, under dependencies, add the lib file like below

example:

implementation 'org.apache.commons:commons-io:1.3.2'
Akshatha S R
  • 1,237
  • 1
  • 15
  • 30
0

You need to the following line in dependencies section in your build.gradle file:

compile files('libs/jarFile.jar')
J.V
  • 1
  • 2