.so文件无法解析相应的JNI函数 [英] Cannot resolve corresponding JNI function with .so file

查看:256
本文介绍了.so文件无法解析相应的JNI函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JNI完全陌生,必须使用现有的已编译.so文件. 问题在于Android Studio无法找到JNI功能. 我在库中加载了与此类似的代码:

I'm completely new to JNI and I have to use an existing compiled .so file. The problem is that Android Studio isn't able to find JNI fuctions. I load my library with a code similiar to this:

public class MyService extends Service{

    static {
        System.loadLibrary("mylib");
    }

    private native void example();

}

它给我一个错误无法解析相应的JNI函数Java_com_company_app_MyService_example".

and it gives me an error "Cannot resolve corresponding JNI function Java_com_company_app_MyService_example".

如果我在终端中运行此命令

If I run this command (in a terminal)

arm-linux-androideabi-nm -DC mylib.so

我得到了(我只需要几个库函数),

I get, between others (I need only few functions of the library),

register_com_company_app_service(_JNIEnv*)

(代替MyService的是服务)

(instead of MyService there is service)

我该怎么办?加载库时还有其他问题吗?

What can I do? Are there problems loading the library or what else?

我也尝试在服务"中添加类名"MyService",但"Java_com_company_app_service_example"也无法解析!

I tried also to refractor class name "MyService" in "service" but "Java_com_company_app_service_example" wasn't resolved either!

提前谢谢!

推荐答案

您需要记住,函数签名必须与Java中的名称匹配,并且必须将其导出.
此外,成员函数将对象作为第一个参数接收,而静态函数将接收类.

You need to keep in mind that the function signature must match its name in Java, and that it must be exported.
Also, member functions receive the object as a first parameter, and static functions receive the class.

#ifdef __cplusplus
extern "C" {
#endif
 JNIEXPORT void JNICALL Java_Namespace_Class_MemberFunction
        (JNIEnv *, jobject);

 JNIEXPORT void JNICALL Java_Namespace_Class_StaticFunction
        (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif

因此,您的情况应该是:

So in your case it would be:

 JNIEXPORT void JNICALL Java_com_company_app_MyService_example
        (JNIEnv *, jobject);

这篇关于.so文件无法解析相应的JNI函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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