BabyishTank
BabyishTank

Reputation: 1482

How to use a class in an imported jar?

What I am doing: Call the method inside the class in a very simple jar from main Activity. (The jar will be used as sdk to make connection with a server but right now is for testing)

Error message Error message This is all the code in my jar, just 1 class This all the code in my jar, just 1 class

I have tried this, and changed the class into singleton pattern and this, and make everything in the class public. I also found this one but same error different issue

Upvotes: 0

Views: 78

Answers (2)

BabyishTank
BabyishTank

Reputation: 1482

In addition to create the class with public modifier, all classes must be warped inside a package. Otherwise it becomes default package and there is no way to access it beside reflection. In another word, when you create the jar, create the class inside a package and Android studio should be able to import the package and use the class inside the jar.

Upvotes: 0

takharsh
takharsh

Reputation: 2688

Create class as public class to make it accessible. In java if you don't provide any access modifier it becomes default.

Refer Java Access Modifiers here

public class Jartest{

  //Your Implementation

}

Upvotes: 1

Related Questions