Compiling an Android System Class

The bytecode for system classes such as android.os.Looper

is just a stub. For example, android.os.Looper.loop()

from android.jar

contains the following bytecode:

public static final void loop();
  Code:
   0:   new     #2; //class java/lang/RuntimeException
   3:   dup
   4:   ldc     #3; //String Stub!
   6:   invokespecial   #4; //Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
   9:   athrow

      

But in AOSP I see the real source code that does the messaging (see AOSP_ROOT/frameworks/base/core/java/android/os/Looper.java

). So how is this class handled exactly by the Android system? Is the real code fixed when the system is compiled android.jar

to a dex file or is it happening at runtime in VM Dalvik?

+3


source to share


1 answer


android.jar

where you compile your code contains only public classes with public (constant) fields and public methods, but none of those methods contain implementation. All return type methods that void

call "Stub!" RuntimeException

...



A runtime library with a real implementation is linked to your application only on a phone device or in an emulator.

+3


source







All Articles