merlin2011
merlin2011

Reputation: 75585

How do I add `odex` files to the classpath for dalvikvm?

This question is a follow-up to my earlier question.

Here is the same example from that question.

import android.os.SystemClock;
/**
 * Command that sends key events to the device, either by their keycode, or by
 * desired character output.
 */
public class MWE {
    public static void main(String[] args) {
        System.out.println(SystemClock.uptimeMillis());
    }
}

After I looked around in my /system/framework directory, I discovered that the class android.os.SystemClock is defined in framework.odex on my phone. I naturally tried the following two command to try to access it.

/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -classpath /system/framework/framework.odex:/data/local/tmp/MWE.jar MWE
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar:/system/framework/framework.odex -classpath /data/local/tmp/MWE.jar MWE

However, both of them resulted in the same error message about not being able to find the class definition.

How do I add such odex files to the classpath for dalvikvm?

Upvotes: 1

Views: 548

Answers (1)

JesusFreke
JesusFreke

Reputation: 20282

Have you tried just:

/system/bin/dalvikvm -classpath /data/local/tmp/MWE.jar MWE

As far as I know, in this case it will pull in the boot classpath from the BOOTCLASSPATH environment variable, which should already contain core.jar and framework.jar.

However, I suspect that will actually result in an UnsatisfiedLinkError exception, because the JNI library that implements some of the native methods in SystemClock won't be loaded.

In that case, there's a handy utility class available that should load the native libraries.

dalvikvm -classpath /data/local/tmp/MWE.jar com.android.internal.util.WithFramework MWE

Upvotes: 2

Related Questions