问题
It is possible to run a plain old java program on android directly without an apk. (see detailed instructions in JesusFreke's comment here: How to execute the dex file in android with command?)
It works like a charm as long as the program uses stock JDK classes. But when I tried to refer to a simple android API like in the code below:
import android.os.Build;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World, API v" + Build.VERSION.SDK_INT);
}
}
... running it following JesusFreke's instructions gives the below error:
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String android.os.SystemProperties.native_get(java.lang.String, java.lang.String) (tried Java_android_os_SystemProperties_native_1get and Java_android_os_SystemProperties_native_1get__Ljava_lang_String_2Ljava_lang_String_2)
at android.os.SystemProperties.native_get(Native Method)
at android.os.SystemProperties.get(SystemProperties.java:64)
at android.os.Build.getString(Build.java:693)
at android.os.Build.<clinit>(Build.java:38)
at android.os.Build.access$000(Build.java:31)
at android.os.Build$VERSION.<clinit>(Build.java:152)
at HelloWorld.main(HelloWorld.java:5)
Is there a way to fix it? More generally, what API(s) are actually accessible when running a program this way?
来源:https://stackoverflow.com/questions/32564192/error-accessing-android-api-when-running-a-java-program-directly-from-dex-archiv