Error loading runtime library in Android Studio

In my Android project, I use an external jar library that uses the libiconv.so runtime library . I have a library included in my lib project directory. A library is included for all three architectures in the following hirarcy directory.

libs> armeabi>libiconv.so armeabi-v7a>libiconv.so x86>libiconv.so 

But I get Exceptions logged by log log:

 05-23 12:18:58.857 3081-3081/? E/AndroidRuntime: FATAL EXCEPTION: main java.lang.ExceptionInInitializerError at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.Instrumentation.newActivity(Instrumentation.java:1054) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libiconv.so from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.tariq.buynow-1.apk,libraryPath=/data/app-lib/com.tariq.buynow-1]: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:365) at java.lang.System.loadLibrary(System.java:535) at com.tariq.buynow.CameraActivity.<clinit>(CameraActivity.java:30) 

Where in CameraActivity.java:30 is:

 static { System.loadLibrary("libiconv.so"); } 

I also tried

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

Is this something related to the gradle configuration since I'm new to Android Studio, or is the source of the errors something else?

+4
source share
3 answers

I had the same problem trying to use the ZBar SDK. Most likely, you will need to edit the build.gradle file to make sure that your own libraries are included in your APK. Here is how I fixed your problem: fooobar.com/questions/328981 / ...

+5
source

System.loadLibrary() looks at the device lib directories, not the application. To do what you need, you need to copy the lib from the application to the phone file system and download it from there. I would suggest installing libs in / res / raw / and doing it like this:

 try { // Point the input stream to the library in /res/raw InputStream is = context.getResources().openRawResource(R.raw.libiconv); // Create a BufferedInputStream from the InputStream BufferedInputStream bis = new BufferedInputStream(is); // Set the FileOutputStream to the app data directory FileOutputStream fos = context.openFileOutput("libiconv.so", Context.MODE_PRIVATE); byte data[] = new byte[1024]; int count; while ((count = bis.read(data, 0, 1024)) != -1) { fos.write(data, 0, count); } fos.close(); bis.close(); is.close(); System.load(context.getFilesDir() + "/libiconv.so"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException ie) { ie.printStackTrace(); } 

This may not work correctly, but the general meaning of this should be.

0
source

Add the following line to your build.gradle scripts

jniLibs.srcDirs = ['libs'] // copy * .so to the package

In the project view you should see: Module / libs / ABI NAME / *. So

0
source

Source: https://habr.com/ru/post/1482383/


All Articles