javaandroidnative-methods

How does Android find out native implementations without calling System.loadLibrary?


I'm digging into Android's kernel to find out the way Binder is done in the Kernel level as well as how it is used in implementing Java's APIs.

Currently I'm looking at android/os/Parcel.java, there's a lot of native functions declared as prototypes like these:

public final native int dataSize();
public final native int dataAvail();
...

but there is no System.loadLibrary so I don't know where the implementations of those prototypes are written.

My question is different from these:


Solution

  • The library doesn't have to be loaded by the class that uses the native libraries. Someplace, in some library, there needs to be a C function Java_android_os_Parcel_dataSize(). It doesn't matter where it is, it just needs to be somewhere. You should be able to use grep to find it.