Is it possible to run Android apps in JVM?
I am trying to run symbolic testing on Android apps to collect some information, for example, the execution tree. Thus I want to run it in JVM instead of the emulator because there are a lot of existing symbolic testing tools for Java applications.
I tried to run HelloAndroid which is a sample app outputting "Hello Android" on TextView by
java -cp ./ -cp $ANDROID_LIB/android.jar HelloAndroid.class
where HelloAndroid.class is compiled Java class before converting into .dex. But JVM is keeping complaining that
Exception in thread "main" java.lang.NoClassDefFoundError: HelloAndroid/class
Caused by: java.lang.ClassNotFoundException: HelloAndroid.class
I am confu开发者_如何学Gosed because I've already specify the HelloAndroid class. And there is no complex statements or calls into Android library in the source code:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
I am new to Android and am struggling to make this small app to execute in JVM. So would you please give me some suggestion? I am wondering if I am on the right way, I mean try to execute simple apps in JVM? Thanks!
Android apps aren't compiled in the same that Java apps are. Android apps are complied down to .dex files, where as regular Java apps are complied to a jar file; neither are anywhere close to being compatible with each other.
The closest currently available thing to running Android apps on a PC is the Android emulator.
So to answer your question, no it is not possible to run Android apps in Oracle's JVM.
精彩评论