没有找到跳过初始化的 JNI_OnLoad >应用程序关闭 [英] No JNI_OnLoad found skipping init > Application shutdown

查看:39
本文介绍了没有找到跳过初始化的 JNI_OnLoad >应用程序关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我正在开发一个需要第三方 .so 库的 android 应用程序.我盖了这个第三方库(带有 ndk-build)按照他们的指示,然后正在寻找将此 .so 包含到我的 Android 项目中.

I am working on an android application where I need a third party .so library. I built this third party library (with ndk-build) as per their instructions and was then looking to include this .so in to my Android project.

因此,我按照 docs/PREBUILTS.html 中描述的步骤成功构建了jni/prebuilt 目录中的新 .so.现在我尝试通过在一个简单的测试 android 应用程序中使用 .so 工具来利用它.所以我要做的是:

Therefore I followed the steps described in docs/PREBUILTS.html and successfully build the new .so in the jni/prebuilt directory. Now I tried leveraging the .so facilities by using it in a simple test android app. So what i do is :

static {
  Log.i("load so > ","load so");
  System.loadLibrary("xyz");
   }
/* The native functions */
private static native int openFile(String filename);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try{
        String path =  getPathForDownloadDirectoryFile();
        Log.i("file path> ", path);
        int num= openFile(path);
    }catch(Exception e){
        Log.e(">", "could not open the file");
    }
}

现在,当我运行我的应用程序时,我会收到一条调试消息:在/data/data/com.example.myfirstapp/lib/xyz.so 0x411e6738 中找不到 JNI_OnLoad,跳过初始化然后应用程序关闭.

Now when I run my app I get a debug message saying : No JNI_OnLoad found in /data/data/com.example.myfirstapp/lib/xyz.so 0x411e6738, skipping init and then the application shuts down.

更多信息,这里是错误日志:

For More Info, Here is the error log :

No JNI_OnLoad found in /data/data/com.example.mysecondapp/lib/xyz.so 0x411e67a0,   skipping init
W/dalvikvm(  570): No implementation found for native    Lcom/example/mysecondapp/MainActivity;.openFile:(Ljava/lang/String;)I
D/AndroidRuntime(  570): Shutting down VM
W/dalvikvm(  570): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
E/AndroidRuntime(  570): FATAL EXCEPTION: main
E/AndroidRuntime(  570): java.lang.UnsatisfiedLinkError: Native method not found:  com.example.mysecondapp.MainActivity.openFile:(Ljava/lang/String;)I
E/AndroidRuntime(  570):    at com.example.mysecondapp.MainActivity.openFile(Native  Method)
E/AndroidRuntime(  570):    at   com.example.mysecondapp.MainActivity.onCreate(MainActivity.java:31)
E/AndroidRuntime(  570):    at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime(  570):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(  570):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime(  570):    at    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime(  570):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime(  570):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime(  570):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  570):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(  570):    at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime(  570):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  570):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(  570):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime(  570):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(  570):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  146):   Force finishing activity com.example.mysecondapp/.MainActivity

正如我所见,openFile() 方法的本机实现未找到,但相同的 xyz.so 库与来自第三方的原始示例应用程序配合得非常好.我几乎是 Android-ndk 世界的初学者.

As I could see that native implementation for the openFile() method was not found but the same xyz.so lib worked pretty neat with the original sample app from the third party. I am pretty much a starter with Android-ndk world.

Java-Android-NDK Ninjas ..猜猜我可能会错过什么?我将非常感谢这里的任何帮助:)

Java-Android-NDK Ninjas ..any guess on what I might be missing ? I'll highly appreciate any help here :)

推荐答案

正如 Guycole 所说No JNI_OnLoad"只是一个警告,你的问题出在其他地方.

As guycole said "No JNI_OnLoad" is just a warning , your problem lies elsewhere .

正如您提到的,您成功编译了so"文件,问题可能在于您的 c/C++ 代码中的函数签名,它应该是这样的

As you mentioned you successfully compiled your "so" file , the problem may lie in your function signatures inside your c/C ++ code it should be something like this

JNIEXPORT jint JNICALL Java_com_your_package_class_method(JNIEnv *d, jobject e, jstring f)
{
//some action

}

函数签名来自使用javah工具生成的头文件.您需要生成头文件并将函数签名与您的包名一起使用.对于不同的包名和类名,头文件和相应的函数签名会发生变化.

The function signatures comes from the header file which is generated using javah tool.You need to generate header file and use the function signature with your package name. For different package and class names the header file and corresponding function signature will change .

worked pretty neat with the original sample app from the third party

这可能是它在示例应用而不是您的应用上运行的原因.

This might be the reason its running on the sample app and not on your app.

参考:https://thenewcircle.com/s/post/49/using_ndk_to_call_c_code_from_android_apps

这篇关于没有找到跳过初始化的 JNI_OnLoad >应用程序关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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