dacongy
dacongy

Reputation: 2552

android system class compilation

The bytecode for system classes like android.os.Looper is simply 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 can see the real source code that performs message dispatch (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 patched in when compiling the system android.jar into dex file or does it happen at run-time within the Dalvik VM?

Upvotes: 3

Views: 646

Answers (1)

Natix
Natix

Reputation: 14257

The android.jar which you compile your code against contains only public classes with public (constant) fields and public methods, but all of those methods contain no implementation. All methods with a return type other that void throw the "Stub!" RuntimeException.

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

Upvotes: 3

Related Questions