Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly means "shared library" when developing in Java for Android? (`*.jar` or `*.so`)

My first guess was that a *.so (unix) or *.dll (win) is a shared library. At least that is my usage writing code in C.

Now the context is developing for Android, which is done in Java->Dalvik style.

I have troubles with a perceived ambiguity of the the term shared library there. In java it seems that *.jar files or *.dex files contain the code that is somewhat both, shared and a library.

Is there a reference to tell what is meant by shared library?

A very specific problem is that Android developers aapt packaging thing is having the option --shared-lib

--shared-lib Make a shared library resource package that can be loaded by an application at runtime to access the libraries resources. Implies --non-constant-id.

which I have no clue what now is meant by shared library. I am aware that there is this JNI interface and some Android NDK stuff might also have *.so files which might be meant, but I am really not sure.

like image 760
humanityANDpeace Avatar asked Jan 19 '26 07:01

humanityANDpeace


1 Answers

On Android developers code in Java, the classes he writes are compiled into Java bytecode (bundled in jar along with other classes automatically created during the building process). once created, this bytecode is translated to Dalvik bytecode (.dex) which is included in the application bundle (apk).

In addition to the Java code, application can be programmed using "native libraries" written in C code and compiled with the android-ndk for the device specific architecture, generating .so files (dynamically linked) or .a libraries (linked statically). Normally this is done for performance issues or reusing libraries written in C and avoid porting them to Java. As you said in the question, this binding is done via the JNI library.

These libraries must be included in the application bundle (apk) and loaded at runtime by the application with System.loadLibrary().

like image 190
Francesc Lordan Avatar answered Jan 20 '26 20:01

Francesc Lordan