Reputation: 21
Hello StackOverflow folks,
I have a jar file of java classes. I added this jar file to my android studio project under folder /libs
. Now, what I want to do is use those classes within the jar file in MainActiviy.java
. I just do not know how.
Some details:
My jar file is named: zombi.jar
.
The class within the jar file to call is named: COMBI.class
I tried the following:
In MainActivity.java
, I wrote:
// declared class variable
private COMBI mCOMBI;
Then, in OnCreate method, I wrote:
mCOMBI = new COMBI();
//to start calling method COMBIStart to launch the command-line system
mCOMBI.COMBIStart();
I actually called the classes as I would in normal Java. I think Android uses special java code that looks like java, but I don't know how to use them.
I could not get the code to work. Can you help me?
Upvotes: 1
Views: 1467
Reputation: 384
I'm going to assume you've already written your import statement for the jar class. If you already put the jar file in the /lib folder, Android Studio should update your build.gradle file. Check to see if you have a link to the jar file in your dependencies{...} If not, you can add it manually.
Upvotes: 1
Reputation: 66
Just like in normal java you have to add an import to the correct package at the top of your file for everything that's not in the same package the file is in.
It should look something like this:
import android.view.View;
but instead of android.view.view it would be a reference to the class in the jar you're trying to add
Upvotes: 0