Android System.loadLibrary stalls while loading native library

女生的网名这么多〃 提交于 2019-12-25 00:05:52

问题


I have a rather large shared library file (= 12megabytes) which does not contain any JNI code whatsoever.

When calling System.loadLibrary("some_file") the method never returns and no relevant output is generated. Also, Windows Taskmanager reports that the emulator instance is not hogging all the CPU power.

I have a class with the following code:

static 
{
    System.out.println("Trying");
    System.loadLibrary("some_file");
    System.out.println("Works");
}

Here is the output given from LogCat:

I/System.out(534): Trying
D/dalvikvm(534): Trying to load lib /data/data/app/lib/libsome_file.so 0x40643c20

If I upload a native test application that uses the library libsome_file.so and run this from the emulator shell, then the application works.

Is there any method to debug what System.loadLibrary is doing or does anyone have some hints why System.loadLibrary might never return?


回答1:


I found the solution to the problem myself. I did not use any additional debug tools, but left out some code that was run when the library loaded. The particular code hanged, making System.loadLibrary hang as well.




回答2:


Adding my solution in case someone else run into the problem. The problem was with some external dependencies (OpenSceneGraph) that were loaded statically in our library. They were only hanging on Android 4.0 and it was running fine 4.2 and up.

So if you have the problem, put a __android_log_print in the JNI_onLoad of your library (if you have one). If it is not called, check all the functions that can be called statically (beware, some might be hidden behind macros) and try to remove them to see if your able to load the library then.



来源:https://stackoverflow.com/questions/8562706/android-system-loadlibrary-stalls-while-loading-native-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!