Android native library dependency not found - android

In my Android Studio project I use a third-party library (which I cannot edit) which requires several native libraries. When I access this third-party library in my app, I get the following error:
java.lang.UnsatisfiedLinkError: Couldn't load avutil-52 from
loader dalvik.system.PathClassLoader
[dexPath=/data/app/com.myApp.debug.apk,
libraryPath=/data/app-lib/com.myApp.debug]:
findLibrary returned null
I use Android Studio 1.2.2, so Gradle supports using a jniLibs folder. My Gradle build file specifies the jniLibs folder, for safety:
android {
sourceSets {
main {
java {
srcDir 'src/main/src'
}
jniLibs {
srcDirs 'src/main/jniLibs'
}
}
}
}
And here I have my libraries:
src/main/jniLibs/armeabi/*.so
The folder includes some other libraries, which are working in the app, so I know the folder is being included.
When I inspect the generated APK, all the *.so files are included in the libs folder. However, when I check the installed app, I only find three of the expected six libraries:
adb shell ls /data/app-lib/com.myApp
first.so
second.so
third.so
I've also checked the /data/data/com/myApp.debug/app_lib/ folder, and none of the other three dependencies are there.
Not being a native Android developer, I find this very puzzling. What could be causing some dependencies to be included, and others to be excluded? Is there a way of forcing Android to recognise the three missing files, and making sure they're installed? Without having to edit the third party library which uses them, of course.
EDIT 1:
Could this code from the third-party library be causing a problem?
public StartFunction() {
String arch = System.getProperty("os.arch");
this.ARM = arch.toUpperCase().contains("ARM") || arch.toUpperCase().contains("AARCH64");
if(this.ARM) {
this.LoadLibraries();
}
}
private void LoadLibraries() {
System.loadLibrary("first");
System.loadLibrary("second");
System.loadLibrary("third");
System.loadLibrary("fourth");
System.loadLibrary("fifth");
System.loadLibrary("sixth");
}
EDIT 2:
This is the full exception from logcat. Package names slightly changed to protect the guilty.
06-30 09:19:08.505 15069-15069/com.myApp.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myApp.debug, PID: 15069
java.lang.UnsatisfiedLinkError: Couldn't load avutil-52 from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.myApp.debug-1.apk,libraryPath=/data/app-lib/com.myApp.debug-1]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.thirdPartyApp.embedded.Call.LoadLibraries(Call.java:289)
at com.thirdPartyApp.embedded.Call.<init>(Call.java:214)
at com.thirdPartyApp.embedded.thirdPartyCall$29.run(thirdParty.java:963)
at com.thirdPartyApp.embedded.DownloadFile.onPostExecute(DownloadFile.java:56)
at com.thirdPartyApp.embedded.DownloadFile.onPostExecute(DownloadFile.java:16)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
EDIT 3:
I've managed to get this working, but in a kind of dirty way. I don't know exactly why this happened, but I do know what happened:
I had all six the compiled libraries needed by the third party SDK I'm using placed in src/main/jniLibs/armeabi. Conventional wisdom dictates that this should work for all ARM devices. However, when installing the app on an ARM device only three of the six libraries were installed.
Dirty solution: place all six libraries in the src/main/jniLibs/armeabi-v7a folder as well. This scattershot approach meant that all six libraries are installed, and available.
I'll update this once we figure out why this happened.

Related

Couldn't load alljoyn_java from loader dalvik.system

i am creating a chat application by using Alljoyn framework and am getting the following error can somebody please help me. The alljoyn jars are already set up!!!
FATAL EXCEPTION: main
Process: com.example.vikesh.chat_application, PID: 4326
java.lang.UnsatisfiedLinkError: Couldn't load alljoyn_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.vikesh.chat_application-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.vikesh.chat_application-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.example.vikesh.chat_application.AlljoynService.<clinit>(AlljoynService.java:1252)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2553)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
You need to put the AllJoyn liballjoyn_java.so file within your project.
For example, in Android Studio, the usual location for this file is:
[your_project_dir]/app/src/main/jniLibs/armeabi/
The armeabi portion of the above path is assuming that the AllJoyn .so file that you have previously built is targeted for the 'arm' CPU (the armeabi instruction set).
Note: When I deleted the .so file from my app, I got the same error that you are reporting. When I put the .so file back I still got the same error. I had to uninstall the app from my Android device, and in Android Studio I had to clean and rebuild the app, before I was able to get past this error.
Some other things to consider...
Make sure in your App that you are calling
static {
System.loadLibrary("alljoyn_java");
}
Make sure that the liballjoyn_java.so you previously built matches the cpu instruction set of your Android device. You can verify your Android's instruction set by using an app such as Droid Info, for example. Assuming that it is armeabi, then when you build the AllJoyn core project, you need to specify at a minimum the following switches in your scons build command....
scons BINDINGS="cpp,java,c" OS=android CPU=arm VARIANT=release
Finally, the following Stackoverflow link discusses general reasons the error you are seeing can occur:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader

Android Tesseract App crashes on OCR Function

I am trying to implement Tesseract into my android project but am getting a crash when trying to complete the OCR.
Here is how I'm setting up Tesseract:
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(imagePath, "eng");
baseApi.setImage(bitmap);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
This is how I'm setting up the image information to pass into the TesseractAPI:
destination = new File(Environment.getExternalStorageDirectory(), name + ".png");
imagePath = destination.getAbsolutePath();
String name = dateToString(new Date(),"yyyy-MM-dd-hh-mm-ss");
Here is the Logcat:
10734-10734/www.rshdev.com.ocr E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: www.rshdev.com.ocr, PID: 10734
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/www.rshdev.com.ocr-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libpngt.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:988)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:43)
at www.rshdev.com.ocr.MainActivity.ocr(MainActivity.java:140)
at www.rshdev.com.ocr.MainActivity.onActivityResult(MainActivity.java:86)
at android.app.Activity.dispatchActivityResult(Activity.java:6192)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3570)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Your tesseract does not crash in the OCR function, it crashes trying to load a library:
java.lang.UnsatisfiedLinkError: ... couldn't find "libpngt.so"
...
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:43)
But line 43 in the source that I have reads:
System.loadLibrary("tess");
therefore it tries to load libtess.so but reports a failure on libpngt.so.
Either:
1) your source code of TessBaseAPI.java is different, it contains System.loadLibrary("pngt"); and that library is missing. Make sure the .apk contains it. Eclipse used to have a misfeature: if your code depends on a library, you configure that dependency for compilation in one place and for delivery in another place. And IIRC .so dependency was specified in a 3rd place.
2) libtess.so is compiled with dynamic linking (try to use static linking then)
3) you are trying to run it in the emulator (try on a real device then).
This is all what can be said from the information you provided.
More info about solution:
I faced with this issue when I moved from Windows to Linux. My Linux had no NDK installed.
I've downloaded it from official source.
Instructions for installing under Linux:
Go to the directory where you downloaded it.
Execute the package. For example:
ndk$ chmod a+x android-ndk-r10c-darwin-x86_64.bin
ndk$ ./android-ndk-r10c-darwin-x86_64.bin
You also need to rebuild tess-two under Linux. Follow the instruction in oficial source.
Make sure that you are using the same gradle version on your project and in the tess lib project. Example:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
The value on classpath must be equals on both projects.
do not update any gradle aur sdk update... i repeat ..do ignore all
the update if asking and it will work smoothly. Just import the
project of priyankverma######## from github and IGNORE all the
updates ... i am sure you wont get this libpngt.so error.
Download or clone the project
import in android studio
let the gradle and sdk versions as it is and
IGNORE all the UPDATES even it is saying "Strongly Recommended.
simply run the project. :)

java.lang.UnsatisfiedLinkError after updating to Android 5.0

I'm developing an Android app which uses a native library called liballjoyn_java.so (available here in the Android Core SDK). I'm using Android Studio as IDE and Maven as build/dependency system (not Gradle). With Android KitKat everything worked like a charm and this is how I added the library to my project:
1) Added the library to my local Maven repo
mvn install:install-file -Dfile=./alljoyn/liballjoyn_java.so -DgroupId=org.alljoyn -DartifactId=liballjoyn_java -Dversion=14.06.00 -Dscope=runtime -Dpackaging=so
2) Defined a dependency in the POM file:
<dependency>
<groupId>org.alljoyn</groupId>
<artifactId>liballjoyn_java</artifactId>
<scope>runtime</scope>
<type>so</type>
<version>14.06.00</version>
</dependency>
3) Called it statically from my code:
static {
try {
System.loadLibrary("alljoyn_java");
Log.d("AllJoynManager", "static - Loaded AllJoyn native library");
} catch (Exception exception) {
Log.d("AllJoynManager", "static - Error loading AllJoyn native library");
exception.printStackTrace();
}
}
This was working perfectly under KitKat in my Nexus 4 phone but now I installed the official Android 5.0 OTA update and I get the following error on runtime:
11-28 17:57:39.988 30068-30068/com.avispalabs.kiihome E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.avispalabs.kiihome, PID: 30068
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.avispalabs.kiihome-2/base.apk"],nativeLibraryDirectories=[/data/app/com.avispalabs.kiihome-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "liballjoyn_java.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
at com.avispalabs.kiihome.helpers.network.alljoyn.AlljoynManager.<clinit>(AlljoynManager.java:38)
at com.avispalabs.kiihome.ui.activities.MainActivity.<init>(MainActivity.java:38)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-28 17:57:55.432 30068-30068/com.avispalabs.kiihome I/Process﹕ Sending signal. PID: 30068 SIG: 9
I suspect the .so library might have been compiled in way which is somehow incompatible with the new Android 5.0 ART (?). The message that says it can't find the library is probably misleading (the exception is also seen when a library fails to load) but I'm not sure (another possibility is the .so is not correctly extracted or placed).
The library comes precompiled and is advertised to be compatible with JellyBean. I thought previous dynamic libraries would be compatible with new versions of Android, otherwise a lot of apps would break. If I install the same APK in a Nexus 4 with KitKat it just works.
Any advice is highly appreciated.
UPDATE: I have tested my project in a KitKat based device and switched the runtime to ART rather than Dalvik, and the project works fine. This problem seems to be tied to Android 5 rather than ART itself.
Answering my own question here. You can solve it by compiling liballjoyn_java as PIE as explained here:
https://jira.allseenalliance.org/browse/ASACORE-1208
This is a workaround until the AllJoyn guys publish a new Android build. Keep an eye here to get the updated release:
https://build.allseenalliance.org/ci/view/Core%20RB14.12%20SDK/job/branch-android-sdk/

Renderscript support v8: Couldn't load RSSupport: findLibrary returned null

I tested the renderscript on my devices (Nexus 4/5/S, Samsung I747). But when I release the beta to people, I collected crashes from various devices, and they're all ARM chip.
Please see the affected devices:
http://crashes.to/s/b7578ea44e5
This is the error:
android.support.v8.renderscript.o: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Couldn't load RSSupport: findLibrary returned null
at android.support.v8.renderscript.RenderScript.shouldThunk()
at android.support.v8.renderscript.RenderScript.shouldThunk()
at com.xyang.android.timeshutter.model.imageprocessing.BaseTwoPassFilterEdgeDetector.()
at com.xyang.android.timeshutter.model.imageprocessing.SobelEdgeDetector.()
at com.xyang.android.timeshutter.model.BaseBitmapPersistentHelper.getBitmap()
at com.xyang.android.timeshutter.model.BitmapPersistentHelper.cropAndSave()
at com.xyang.android.timeshutter.model.BitmapPersistentHelper.readCompressedImageDataFromUri()
at com.xyang.android.timeshutter.app.capture.FreeCropFragment.onClick()
at android.view.View.performClick(View.java:4100)
at android.view.View$PerformClick.run(View.java:17021)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4788)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:541)
at dalvik.system.NativeStart.main(NativeStart.java)
I know there're some bug for the Intel x86 devices, but why ARM devices also get this link error?
It looks like you didn't include the JNI libraries as part of your application package. Please check that you didn't accidentally strip them. You should have libRSSupport.so, librsjni.so, as well as a librs..so for each user script you have in your application. These should exist under the lib/armeabi-v7a directory for any ARM device. There should also be similar subdirectories for x86/mips.

Android ndk 8b Cannot load library

Upgrading to ndk 8b I receiving some crash report (most of them are Galaxy SII with Android 4.03)
java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1286]: 1836 cannot locate '__gnu_thumb1_case_uqi'...
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at com.iuculano.fplayer.SDLActivity.void onCreate(android.os.Bundle)(SourceFile:324)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
The exception is caused by a simple System.loadLibrary("main");
What does it mean? cannot locate '__gnu_thumb1_case_uqi'
The __gnu_thumb1_case_uqi is a helper which does an indexed jump on a densely packed switch table; quickly implements the switch. You have two options: avoid it or link with it.
If you increase an optimization level (by using -O3) you might not need this symbol. Also, changing the CPU may help as well as using thumb2 instructions. Compiling with the -ffreestanding option may also avoid this symbol. If you have control over the switch statement, you can replace it with an array of function pointers.
This routine is inside libgcc. You can statically link libgcc. Somewhere in the Android SDK/compiler, there must be a libgcc.a. Link with libgcc.a, using -L and -l or use -static-libgcc linker option to get the code (see http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html).
Edit: If you aren't compiling anything, then you can find libgcc.so on your system. It might be in /lib or /usr/lib or perhaps some place weird for Android devices. Adding the directory where the libgcc.so is located to the environment variable LD_LIBRARY_PATH could also fix the problem. It maybe unfortunate that Samsung released incompatible binaries and you have no way to fix the issue if you aren't compiling your own code. The correct libgcc.so maybe inside something like /usr/lib/thumb for multi-lib distributions. I don't know much about the Davlik stuff, but the Android JVM might not pointing to the right set of libraries when it runs.
Are you compiling for armv7? If you're not, try compiling for armv7.
Producing optimised NDK code for multiple architectures?
read about 'arm' vs 'thumb' in the accepted answer in the above link.
then, remove your config instructions to build for thumb and verify that you are building for arm...
OR...
ill make a wild guess ... its the library order you have in the linker statement in your 'Android.mk'
try the google forum for ndk ... searching for 'cannot locate symbol'...
Really desperate?
see 'Runtime errors' section here

Categories

Resources