从robovm项目创建iOS静态库(JNI中的BAD_ACCESS) [英] Create iOS static library from robovm project (BAD_ACCESS in JNI)

查看:72
本文介绍了从robovm项目创建iOS静态库(JNI中的BAD_ACCESS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的Java代码(只有计算功能,没有UI),我想将它们作为iOS中的静态库重用.我的方法是使用 robovm 并遵循非官方的方法来创建robovm论坛的两篇文章中描述的静态库. : 1种基本方式

I have a large amount of Java code (only calculation functions, no UI) that I want to reuse as a static library in iOS. My approach was to use robovm and follow the unofficial way to create a static library described in the two articles in the robovm forum: 1 Basic way and 2 Refined version

尝试完全按照描述的步骤进行操作,不幸的是,在使用脚本创建共享库,在Xcode中链接库(.a)并成功构建项目之后,我陷入了困境.

Trying to follow the steps exactly as described I got stuck unfortunately after creating the shared library with the script, linking the library (.a) in Xcode and building the project successfully.

在运行时,我看到我的C ++桥代码被调用了,但是回该库的JNI调用却失败了,并显示了BAD_ACCESS.例如,以下行崩溃:

During runtime I see that my C++ bridge code is called but the JNI calls back to the library fail with a BAD_ACCESS. For example the following line crashes:

jclass myJavaClass = jniEnv->FindClass("com/test/robovm/bridge/MyJavaRoboCode");

在这种方法中:

void callSomethingInJava(const char* arg) {
    // To call into java from your native app, use JNI
    Env* rvmEnv = rvmGetEnv();
    JNIEnv* jniEnv = &(rvmEnv->jni);
    jclass myJavaClass = jniEnv->FindClass("com/test/robovm/bridge/MyJavaRoboCode");
    jmethodID myJavaMethod = jniEnv->GetStaticMethodID(myJavaClass, "callJava", "(Ljava/lang/String;)V");
    jstring argAsJavaString = jniEnv->NewStringUTF(arg);
    jniEnv->CallStaticVoidMethod(myJavaClass, myJavaMethod, argAsJavaString);

}

如果我尝试直接使用rvmXX方法而不是JNI并尝试访问"Java"类中的内容,则情况也是如此.看起来rvmEnv尚未完全初始化. (我仔细检查了程序包名称错误或拼写错误.)

The same is true if I try to use the rvmXX methods directly instead of JNI and try to access something in my "Java" classes. It looks like the rvmEnv is not fully initialized. (I double checked for package name errors or typos).

如果有人已经成功地通过robovm项目创建了共享静态库,并且可以在这里分享经验或为我指出解决问题的正确方向,那将是很好的选择.

It would be great if someone already succeeded with the creation of a shared static library from a robovm project and could share the experience here or point me in the right direction to resolve the issue.

推荐答案

您提到过,您可能尚未完成robovm的初始化.

As you mentioned, you probably haven't finished initialising robovm.

您需要创建一个方法,例如initRoboVM(),以略微反映bc.c的主要方法.当您要初始化robovm时,您的代码将调用此函数.您需要传递应用路径,您可以在测试时对其进行硬编码.

You'll need to create a method, say initRoboVM(), to somewhat mirror bc.c's main method. This will be called by your code when you want to initialise robovm. You'll need to pass the app path in, which you can hardcode when you're testing.

initRoboVM()将需要进行一些修改,即它不应该调用Java应用程序的main方法,至少,这就是行为库不应该执行IMO的方式.它也不应调用rvmShutdown.

initRoboVM() will need some modifications, namely it should not call your Java app's main method, well, at least, that's what well behaving libraries should not do IMO. It should also not call rvmShutdown.

这篇关于从robovm项目创建iOS静态库(JNI中的BAD_ACCESS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆