Android Ndk Library Is Not Loading On Runtime For Samsung Galaxy 4.0.2 Phones Only
Solution 1:
There is a known bug on Android 4.0 with native libraries loading which may be the cause of your problem. I wrote a detailed blogpost on it if you want to dive into the details. Long story short:
I guess the library you're trying to use is compiled for different architectures (generally armeabi and armeabi-v7a, respectively stored in libs/armeabi
and libs/armeabi-v7a
). On Android 4.0, the System.loadLibrary()
method is messed up: when you try to load library libsomething.so
, instead of searching for the native library in the folder corresponding to the architecture of the device, it loads the first library with name libsomething.so
it finds in any libs
subfolder, potentially loading the wrong architecture, which can cause such a crash.
The simplest workaround:
- Give different names to the libraries depending on their architecture, for example
libsomething.so
for armeabi andlibsomething-v7a.so
for armeabi-v7a. That way, when usingSystem.loadLibrary()
, it can't get confused by the fact that several files have the same name. - Once this is done, the problem is that you must know which one of these two filenames to load with
System.loadLibrary()
, i.e. you must detect the architecture used by the device by yourself. There are several ways to do that: one of them is to use theandroid_getCpuFeatures()
from thecpu-features.h
file from native code (explained in the above blogpost), another is to parse the system/proc/cpuinfo
file from Java (for example as explained here)
Hope this helps!
Post a Comment for "Android Ndk Library Is Not Loading On Runtime For Samsung Galaxy 4.0.2 Phones Only"