I have an android project and I added an external .jar file which contains several .class files and in addition some .so files.
When I try to use some methods which are provided by the .class files I get a UnsatisfiedLinkError-Exception which says that the implementation for those methods couldn't be found.
Obviously the problem is that the .so libraries which contain the implementation were not correctly loaded/cannot be found.
What do I have to do that the native libraries in the external .jar file can be found from the runtime?
More details:
I'm using AndroidStudio and the app is tested on the emulator with the device "Nexus 5 API 23 x86". The .so files support x86 too.
I copied the .jar file into the /app/libs folder. Then I right-clicked the file in the IDE and selected "Add as library".
As you see that crash is saying that it could not load native library. But why?
First of all I checked my structure, If native library .so files located correctly.
Seems everything was okay except this crazy error.
Then after some research, I find out that some of android devices has 64-bit processors.
This devices generates and check arm64 folder to load native library.
That was the problem. Because my project does not have arm64 folder.
Here is the solution;
defaultConfig{
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}
}
Related
I have created a spring application which uses google or-tools. For that, I am importing jniortools using System.loadLibrary("jniortools"). when I provide the .dll file and run the war file it runs perfectly. But when I provide the .so file path in lib, I get the unsatisfiedlinkerror.
Taken from here, a solution for using or-tools over Intellij:
To make it work using Intellij (over a windows machine) you need to:
Install Microsoft Visual C++ Redistributable for Visual Studio
Download and extract the OR-Tools library for Java
In intellij, add jar dependency to the 2 jars under the lib folder of the extracted files (each of the 2 jars separately, do not add to lib folder itself. This is why).
Add the lib library path to VM options. In Intellij edit your run-configuration and add to vm options: -Djava.library.path=<path to the lib folder that hold the jars>
Load the jni library statically by adding the below code to your class (as mentioned here.)
static {
System.loadLibrary("jniortools");
}
I have added below line of code to generate 64 bit lib files,But still so of the lib files are missing in 64 bit folders, How can I add those missing libraries? Do I need it add those libraries externally.
Code:
ndk
{
abiFilters "armeabi-v7a","arm64-v8a","x86","x86_64"
}
You'll need to generate your 64-bit so using
Create Application.mk inside your jni folder, where your native files are present
paste this APP_ABI := all in the Application.mk file. Save it.
Run ndk-build in the jni folder where your Application.mk is present.
If you've configured your =>Android.mk with current modules you'll get so's for all the architecture in libs or jniLibs directory.
I am using a library in my project to play videos. The library comes up with a demo project. The demo project is working fine.
The library has few .Jar files, some library classes, and a lot of .so files. The demo project put the Jar files in lib folder and .so files in armeabi and x86 folder.
I did the same, but it start giving me following error message.
UnsatisfiedLinkError (Can't find dependent libraries)
Then i put these .so files in armeabi-v7a folder, and the error is gone.
but still its not working completely fine.
Its not giving me any error message, but still its also not initializing the class that is available in the Decompiled.class file. The same class is initializing successfully in demo project. I found out this problem after debugging both projects.
I have checked each and everything, the only difference i can see in demo and my project is armeabi-v7a and armeabi.
So do files compiled for armeabi have some problems with armeabi-v7a, or it can be some other problem.
arm-eabi vs armeabi-v7a should not be the problem. At the low level, armeabi-v7a is compatible with armeabi, but not vice versa.
Can you add more debug and give more info?
I have a strange error: I want to use Java3D but Eclipse gives me following error about the library .so file
Archive for required library: 'libs/libj3dcore-ogl.so' in project 'MyTest' cannot be read or is not a valid ZIP file
I'm using Ubuntu 14 LTS 64bit so I've downloaded the amd64 version of Java3D 1.5.1:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-client-419417.html#java3d-1.5.1-oth-JPR
regards
You are not supposed to import .so files to eclipse as libraries. This is a native file, shared library to be exact. It needs to be linked at runtime using:
System.loadLibrary("j3dcore-ogl");
You need to find a .jar file, which you should put into eclipse as library instead of the .so file. Then you can either attach this file to your library, or link it during runtime yourself.
I have downloaded code http://code.google.com/p/aacplayer-android/downloads/detail?name=aacplayer-android-r25.zip&can=2&q= for playing AAC file in ANDROID
and below is image of that code in eclipse
Here you can see that there is jni folder and libs folder in LIBS folder also contain .so files
Currently i have not installed any NDK and i have imported this project which is working fine...
but if i use this files and code into my project should i have to install NDK?
I have copy and paste this jni and libs folder to my application, now what should i have to do! How to tell my apps that this is the native code!
my apps folder structor is (after copy paste) below
If you do not want to rebuild the .so files you should not need the NDK. Eclipse/Java/Android will handle them as fine as native java libraries. You need the ANdroid NDK if you want to be able to compile c/c++ code for the android platform.