3

I'm currently working on a java library (binding) which uses some own written native code. This native code is compiled as a .so file for multiple architectures (arm-v7, i686, x86-64, etc).

I know in android you have to create a folder called jniLibs with subfolders for each architecture containing the proper .so file. Then with an Android.mk file and System.loadLibrary I can include these files into my code.

However, I have no clue how to include these .so files in a normal java project/library. I have read online that System.loadLibrary only works for looking through normal files (and not necessarily project files).

Max
  • 2,354
  • 2
  • 14
  • 27
  • 1
    So your single jar is meant to "cross-deploy" across both Android and regular desktop/server Java environments? That's ... ambitious-sounding. – unwind Jun 16 '16 at 10:27
  • 1
    @Max : Please check this : http://blog.guillaumeagis.eu/setup-andengine-with-android-studio/ – AndiGeeky Jun 16 '16 at 10:27
  • 1
    This somewhat contradicts the "compile once, run everywhere" idea of Java. Anyway, that is not related to C. Shared libraries are no way C-specific. – too honest for this site Jun 16 '16 at 10:45
  • That is my goal, yes @unwind – Max Jun 16 '16 at 10:54
  • @AndiGeeky This post is for android, which I got it working for already. My question is aimed more towards java itself. – Max Jun 16 '16 at 10:56
  • @Max : Oh.. then sorry buddy..!! – AndiGeeky Jun 16 '16 at 11:02
  • OK, now it sounds like an [XY problem](http://xyproblem.info/). What is the problem you are trying to solve (X)? Attempting to solve it with a single distribution (Y) sounds hard and has a low payoff. – weston Jun 16 '16 at 11:12

2 Answers2

1

You can't have anything other than code in an android .jar file, however, you can have resources in an .aar file.

Android Archive Library (aar) vs standard jar

You will find that the .aar for your library is the redistributable/reusable compiled version of your library.

Community
  • 1
  • 1
weston
  • 54,145
  • 21
  • 145
  • 203
  • Thankyou for this article, it sure helped me understand the difference between a `.jar` and `.aar` more. However, is there a work-around on how I can deliver my native code with a `.jar` in a user-friendly way? – Max Jun 16 '16 at 10:57
  • You must use aar files. Doesn't get more user friendly than that. They replace jar files, so it's still a single file to distribute. – weston Jun 16 '16 at 11:08
0

You can do it as how SWT did it -- extract the library files from your .jar file to user's home directory (so you are sure you have access to write in it) manually by java code. You can check the source code of org.eclipse.swt.internal.Library, method extract().

lei zhou
  • 1
  • 2