简体   繁体   中英

How to run jar file within Android Studio?

I have a jar file of java classes. I want to create an apk of my jar file. I know how to add libs folder into my android project, but I do not know how to make connections. I need to refer to my jar file in MainActivity.java, as well as in AndroidManifest.xml? What should I write in these two files? Indeed, I spent good time googling for an answer and reading posts on stackoverflow and others, but I did not find the specific answer for my question.

I hope you can help me. Lina

Copy and paste the .jar file into libs folder of your Android Project. Then open your gradle.build(Module:app) and then you can see .jar in dependencies{}

Now you can use classes which are reside in .jar file. Hope this helps you...

Copy the .jar file to clipboard then add it to libs folder.

To see libs folder in the project, choose the project from the combobox above the folders. Then right click on the .jar file, and click "add as a library" then choose a module then press ok.

You can see the .jar file in build.gradle file within the dependencies block.

I do not know how to call the classes within the jar file which is added to gradle.build. What i tried is:

My jar file is named zombi.jar and contains the class combi which i want to execute.

In MainActivity.java, I defined a variable like this: private COMBI mCOMBI; (COMBI IS THE CLASS I NEED TO CALL WITHIN THE JAR FILE) In onCreate method, I added a call to combi like this: mCOMBI.COMBIStart(); (COMBIStart is the method within combi class that will execute the project).

I got errors all over the place. What to do? Lina

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM