4

I have cross compiled the native code for different architectures for android and have its corresponding jni wrapper class working in android studio. Now I want to make it available as a library. I have two questions:

1)Can I just jar the .so file and jni files to make the library?(not .aar because my library contains only the pure java and native code, no android related stuff such as .xml,res,etc) If so what should be its structure?

2) If I cannot create .jar file, then all I am left with is creating the .aar file. That would include the use of android studio. Can I do it without the android studio?

Edit 1: If I jar the files, then I don't want to extract .so and then use it. If I jar the files, then add it(the .jar) as a dependency in my project then it should automatically put .so into libs/jni folder in my apk so that jni can find it. Question is how do I do that?(if possible)

2
  • I believe you should be able to add the .so file and the Java files to the library. However, to be able to use the .so file in the jar you need to unpack it to a location on the device to the load the library. I haven't tested it yet but I'll post an answer if I get a chance to make sure it works. Commented Jun 30, 2016 at 21:28
  • Are you talking about this adamheinrich.com/blog/2012/12/… ? I don't want to do that. If I jar the files, then add it as a dependency in my project then it should automatically put .so into libs so that jni can find it. Commented Jul 1, 2016 at 7:10

1 Answer 1

5

Fortunately found a way. As .aar is itself a simple zip file with structure as specified here. What I did is "jar" all the .class files (inside proper package folder) into classes.jar, created an empty folder "res", put all .so files in jni folder (with proper architecture) and made a simple AndroidManifest.xml containing basic tags. Then I jar them into file with extension .aar (like mylib.aar). I have tested it by copying .aar into another project's libs folder and putting a dependency on it in app's build.gradle( like compile(name:'mylib',ext:'aar')). And it works great.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.