开发者

Is it possible to run Android apps in JVM?

开发者 https://www.devze.com 2023-04-12 05:30 出处:网络
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 existi

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消