UnsatisfiedLinkError in Android application with my JNI libraries - android

I am making an application that uses some JNI libraries built for an another app. I have, of course, imported all the necessary Java calsses to my application while keeping the package names the same. I have two libraries imported:
libopencv_java3.so
libopencv_xfeatures2d.so (I built this for an another project)
When I go into my old application, all the libraries load fine, but in this one I do not get any errors regardin loading the libaries themselves, but i only get errors regarding the acutal methods. This happens only with my library, as all opencv_java3 calls seem to work fine. I have placed all of the .so files in the jniLibs folder, and I checked the apk to see if they were packaged correctly, and everything seems fine there. Anybody else having my same issue?
BTW I am using Android Studio 1.5.1, libraries built with NDK r10 with target API 15 (which is also the minimum API for the application).

Related

How to add vendor shared lib to android ndk app

I have added a library under Android aosp vendor folder and successfully created shared lib (lets say, libmyvendor.so) files. And verified that .so files are created under both system/lib and system/lib64. Flashed on a device and working fine here.
To debug my ndk application, I have copied .so files into Android's path sdk/ndk/{versionNumber}/platforms/android-28/arch-x86/usr/lib. Also in archx86_64/usr/lib64 folder. Did invalidate and restart Android Studio. Now I'm trying to find or add libmyvendor library in my ndk application using cmake function
find_library(mVendor libmyvendor)
Tried myvendor instead of libmyvendor. In both cases, cmake couldn't find it.
Then tried copying libmyvendor.so files into ndk application (under jniLibs/x86/ and x86_64/ ). Compiled but app crash at runtime saying
UnSatifiedLinkError: dlopen failed library 'libcrypto.so' not found
Where libcrypto.so is needed as a dependent to libmyvendor project. And I'm stuck here.
As per my assumption, libmyvendor is part of system libs. NDK should be capable of finding it using find_library(), just like we find liblog.so. But it cannot find. Did I miss or mess anything?

create a nativescript plugin for Android with compiled C files

I'm trying to create a nativescript plugin, following the official documentation here
I created my .aar file and copied it into the platforms/android folder, which is working when I call my plugin class. The problem I'm facing is when I try to call a function that loads a native library, giving me a UnsatisfiedLinkError.
I've already seen these links 1 2 and tried all the options mentioned, but none of them seems to work. Since those links are two years old, I wonder if these methods are now deprecated.
My tns version is 4.1.2 and tns-android is 4.1.3.
I've tried adding the *.so files to the following folders:
platforms/android
platforms/android/libs
platforms/android/libs/armeabi
platforms/android/libs/jni
platforms/android/libs/jni/armeabi
platforms/android/armeabi
platforms/android/jni
platforms/android/jni/armeabi
platforms/android/jniLibs
platforms/android/jniLibs/armeabi
As you can see, I've tried all possible combinations based on the previous posts (my *.so files are for armeabi architecture)
Note that the only case that don't fail as the others is platforms/android/jniLibs/armeabi. While trying this one I got an error telling me that one of the .so files is repeated (merge conflict) when calling tns debug android, the other ones just fail on runtime when I call the function
I believe linker error is totally from your native library. Your call from plugin to native Java class is successful here, Java to C seems to be the issue.
Did you verify whether your native library (.so files) were compiled successfully, may be by importing them in a simple Android app? If it still fails, then it has nothing do with {N} runtime but may be something with NDK compilation.

Debug Android Native located in dependent eclipse project

(ADK 21, NDK r8d, Eclipse Juno)
[I've built several Android apps so decent experience using ADK/NDK etc]
Eclipse project setup:
- AppProject (android, java, no jni)
- LibProject (android, java, Yes jni)
Previously, all of it was in one project - builds fine, runs fine, and native debugging worked great.
Then I split off the "reusable" portion to make a library of common code to use with multiple "AppProject" application front ends. (Everything still builds, links, packs, and runs okay)
However, when I run "AppProject", I can no longer debug the native library.
What is the solution?
Possible option #1:
- Modify "LibProject" Android.mk to export a PreBuilt that is used by AppProject?
- (I would have all the debug symbols so I'm thinking that would work okay)
Would I need to cnature the AppProject as well? In other words, so it has an Android.mk to import the output .so from LibProject
Possible option #2
- http://stackoverflow.com/a/14344377/735533
- that workaround uses ndk-gdb
- I'm hoping for a solution where I can debug LibProject in Eclipse directly when running AppProject
Is there a better way to debug the native code located in the dependent project "LibProject" when running the main application "AppProject"?
Tia
For those curious ...
I tried prebuilts ...
And it definitely seems the be the way to go (test project setup worked)
But the structure of my codebase is a bit heavy on the native/non-native crosstalk and didn't want to take the time (yet) to do a proper reorganization at the moment.
However, restructuring as a prebuilt is on my "Important ToDo" list now
Anywhere, here is my solution.
On Linux (unix flavors) ... use links - the sources are linked into each AppProject from LibProject.
Basically the "LibProject" becomes a sort of "template" during development - it is not built or used as a library directly. Rather, each AppProject becomes self-sufficient, standalone, application with the contents of the library project embedded in its own code tree. Best part is native debugging works like a charm again.
Although it sort of defeats the point of making, there are benefits - one common codebase for the "library" portion ... which is really what I desire for the time being.
Also, conversion to use as a true Library dependency by the Application projects for, say, eventual release builds is an easy switch. Once debugged and ready, the Library can be built separately, packed normally with the application "front ends", and upgraded independently of the applications.

Sharing Java library with Android Apps

I'm just getting started in Android development, and use Netbeans with NBAndroid and SDK 17.
I'd like to use the same Java source code in my Java and Android app.
http://developer.android.com/guide/developing/projects/projects-eclipse.html says how to do it in Eclipse (although it is sketchy on the .JAR connection thing), but I can't seem to make it work in NB.
Based on that link, My understanding is that the correct setup for the Android app is an Android Application project which references an Android Library project which in turn references a .JAR library produced by a Java Library project. I could then also have a Java Application project referring to the same Java Library project.
So, I've set up this project structure... I have an AndroidApp project which is a basic HelloAndroid Activity in a com.ex package. This project includes an AndroidLib library project in the Libraries folder. I also have a LibClass.java file which defines a simple LibClass class which has one function getText() that just returns a String to be displayed. The MainActivity in the AndroidApp calls this to get the String to output.
When I put LibClass.java directly into the AndroidLib project, everything is fine.
But what I want to do is to share the source code with Java.
So I want to move the LibClass.java into the JavaLib library, whose .JAR file is included in the AndroidLib project. However, when I tried that, I get an error in the MainActivity class, complaining it can't find LibClass. Looking at the Projects window, I can see LibClass.class inside the com.ex package in the JavaLib.jar in the Libraries folder of the AndroidLib project. And AndroidLib is visible in the Libraries folder of the AndroidApp project, but it doesn't show any packages or other contents there.
So I feel like I'm just one step away from making this work. Do I need to do something with one or other of the AndroidManifest files perhaps? Or do something with the build.xml files? Or am I on the wrong track altogether?
I'd be really grateful if someone could post a how-to for this.
I'm trying something similar; I've got Java EE projects, built using Eclipse, and I'm trying to utilize some of that code from my Android projects. This should give me a shared codebase rather than a bunch of confusing SVN externals which I've had to endure before.
Rather than creating JAR files I've found that working with the source and building for the platform works best (well, it has been working but I've got a problem with it at the moment). So, what I'm doing is:
c:\MySvnFolderStructure\MyJavaProjectFolder\src\ (and then all the source under that)
c:\MySvnFolderStructure\MyJavaProjectFolder\android\ (and all the Eclipse Android project gubbins)
c:\MySvnFolderStructure\MyJavaProjectFolder\jee\ (and all the Eclipse JEE project gubbins)
The Android and Java EE projects do not have their own src folders, they both link to the src folder in their parent folder. What this means is that each of the Java implementations is building its own byte code version from the source, and using its own external libraries (like the Apache HTTP ones, for example).
Naturally they can't share stuff like awt (as mentioned in another post), but there's plenty of stuff that does cross-over especially if it's core Java classes that are being used.
Also, it's proving a bit tricky writing JUnit tests as there needs to be some duplication of the test code at the moment because the Android ones need extra instrumentation, but I'm working on it.
Also, see this post about relative paths in Eclipse, which means the folders can be checked-out to different places on different machines (like we all do with our version control check-outs) and still be shared.
if I understand your situation correct, you are trying to use a custom java library for both your android and java applications.
For this scenario, you can build the java library first. Instead of adding the java library jar as android library, you can drop the jar directly inside the libs folder of android project and add it to android project's build path.
If you are using ANT scripts for building the java library jar , you can consider adding the source files also as part of jar. This will help you get code assistance when you develop the android part. But this part is purely optional.
The problem is that the Java platform in Android is different from the JDK platform.
In particular, the .JAR library CANNOT refer to anything that is not icluded in the Android platform. An example of things you can't refer to is java.awt.* (except you can have java.awt.fonts).
There is also a difference between JDK String and Android String -- Android does not implement the isEmpty() method.

Android NDK doesn't link static library

Some mystery is going on with my project :)
I have a shared library that uses libjpeg which is static library. It all worked fine but now when I need to add a few changes to the project it just stopped including libjpeg in my shared module.
So before when it worked, my shared module (.so file) was around 90Kb and now it 4Kb and application can't run saying that it can't find libjpeg.so
And folders structure is following:
/platform/libjpeg - include files for libjpeg
/platform/libraries - contain libjpeg.a and a few other libraries
UPDATE: After playing around with the projects I figured out that the problem appeared after I wanted to add android:installLocation into manifest. Following Google's recommendations for backward compatibility (http://developer.android.com/guide/appendix/install-location.html) I changed project's API level to 8 (so it parses manifest without errors) and left minSdkVersion="7" (so it runs on previous version). However, this particular change in the project affects the NDK build. Probably, libjpeg is included in android-8 and it doesn't want to build it in as a static library?
Anyway, the question is: Is it possible in eclipse to ignore error about installLocation in manifest using API level 7 or is it possible to force ndk-build to use API level 7 while keeping level 8 in the project settings?
In NDK you can find document docs/ANDROID-MK.html. In this document you will find option TARGET_PLATFORM. This should help.

Categories

Resources