Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

想咨询android端的问题 #18

Open
liqihui1 opened this issue Jan 29, 2023 · 1 comment
Open

想咨询android端的问题 #18

liqihui1 opened this issue Jan 29, 2023 · 1 comment

Comments

@liqihui1
Copy link

我的目的是想在data/data/xxx/files目录下放入.jar文件,然后通过miniJVM来执行改.jar文件中的类。
android端要怎么做

@digitalgust
Copy link
Owner

digitalgust commented Feb 3, 2023

minijvm 有两种适配android的方式, 第一种,是直接把minijvm作为一个android App, 打包后可以直接运行,这个app自带图形界面,这种只需要用android studio打开 /mobile/androidapp就可以了,这时只需要开发一个继承于org.mini.apploader.GApplication的图形应用,直接在minijvm的图形界面安装你开发的图形应用jar即可.这个应用如果有库,只需要在打包时把jar库放在应用jar文件根下的lib目录中

如果有自己的jar库可以放在 /mobile/assets/resfiles下,需要修改一下/mobile/c/glfmapp/main.c 在
utf8_append_c(classpath, "/resfiles/glfm_gui.jar;/resfiles/yourjarname.jar");分号后加上你自己的jar路径.

另一种是你有自己的app 已经开发了很多别的功能,把这个minijvm作为一个native模块使用(仅使用/minijvm/c里面的代码,使用/minijvm/java作为运行时jar基本库), 编译进你自己的.so中, 你需要写一个简单的jni接口来启动这个minijvm,但是这个作为模块的minijvm,无法使用图形界面, 因为minijvm使用opengl es3.0作为图形界面的基础, 而这个opengles图形界面只能用c语言创建.

一个简单的例子,未经测试.

#include "jvm/jvm.h"

int calljvm(char *path) {
    char *bootclasspath = "../../binary/lib/minijvm_rt.jar";
    char *classpath = path;
    char *main_name = "test.Foo3";

    s32 ret = 1;
    MiniJVM *jvm = jvm_create();
    if (jvm != NULL) {
        jvm->jdwp_enable = 0; //value 1 for java remote debug enable
        jvm->jdwp_suspend_on_start = 0;
        jvm->max_heap_size = 25 * 1024 * 1024; //

        ret = jvm_init(jvm, bootclasspath, classpath);
        if (ret) {
            printf("[ERROR]minijvm init error.\n");
        } else {
            ret = call_main(jvm, main_name, NULL);
        }
        jvm_destroy(jvm);
    }
    return ret;
}

JNIEXPORT jboolean JNICALL Java_org_minijvm_activity_JvmNativeActivity_onStringInput(JNIEnv *env, jobject jobj, jstring s) {
    int down = 0;
    if (platformDataGlobal && platformDataGlobal->app) {
        const char *rawString = (*env)->GetStringUTFChars(env, s, 0);
        calljvm((char *)rawString);
        (*env)->ReleaseStringUTFChars(env, s, rawString);
    }
    return down;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants