没有JNI_OnLoad发现跳绳INIT>应用程序关闭 [英] No JNI_OnLoad found skipping init > Application shutdown

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

问题描述

伙计们,

我工作的一个Android应用程序,我需要一个第三方.so库。我建 这个第三方库(与NDK建造)按他们的指示,然后寻找 包括在我的Andr​​oid项目这个。所以。

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.

所以我也跟着在文档/ preBUILTS.html中描述的步骤,并成功打造了 新的。所以在JNI / prebuilt目录。现在,我试图通过一个简单的测试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");
    }
}

现在,当我运行我的应用程序,我得到一个调试消息说: 没有JNI_OnLoad在/data/data/com.example.myfirstapp/lib/xyz.s​​o 0x411e6738发现,跳绳的init 然后应用程序关闭。

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.s​​o LIB工作pretty的整洁与来自第三方的原始样本应用程序。我是pretty的多少与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的Andr​​oid的NDK忍者..any想什么我可能会丢失? 我会高度AP preciate任何帮助此处)

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

推荐答案

由于guycole说:不JNI_OnLoad只是一个警告,您的问题不在于此。

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

正如你提到你成功编译你的这样的文件,问题可能在于你的函数签名你的c内部/ C ++ code就应该是这样的。

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的tool.You需要生成的头文件,并使用该函数的签名与你的包名头文件。对于不同的包和类名头文件和相应的函数签名会改变。

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发现跳绳INIT>应用程序关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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