Android Question so library Files

jkhazraji

Active Member
Licensed User
Longtime User
Where to place the .so library file which is necessary for opencv-4.9.0.aar file to work?
 

jkhazraji

Active Member
Licensed User
Longtime User
If the so file is inside the AAR and in the correct folder then it should work as-is.

It should be under jni\<cpu type>

SQLCipher is an example of a library with so file.
Thanks @Erel for your prompt response.
With the following code :
B4X:
#AdditionalJar: opencv-4.10.0.aar
'
'
'
'
Sub Button1_Click
    Dim ocvJava As JavaObject
    ocvJava.InitializeStatic(Application.PackageName & ".main$OCVClass")
End Sub
'
'

#if java
import org.opencv.core.*;

public static class OCVClass {
    // Static block to load OpenCV library
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
}
#End If
I had the error: couldn't find "libopencv_java4100.so
B4X:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/b4a.example-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-2/lib/x86_64, /data/app/b4a.example-2/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]] couldn't find "libopencv_java4100.so"

opencv-4.10.0.aar was downloaded from official OpenCV site and it contains jni with the following cpus:
1734870573405.png

and x86_64 has the following .so files:
1734870622875.png
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I had the error: couldn't find "libopencv_java4100.so
B4X:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/b4a.example-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-2/lib/x86_64, /data/app/b4a.example-2/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]] couldn't find "libopencv_java4100.so"
Try this
B4X:
#if java
import org.opencv.core.*;

public static class OCVClass {
    // Static block to load OpenCV library
    static {
        System.loadLibrary("opencv_java4");
    }
}
#End If
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Try this
B4X:
#if java
import org.opencv.core.*;

public static class OCVClass {
    // Static block to load OpenCV library
    static {
        System.loadLibrary("opencv_java4");
    }
}
#End If
Thanks a lot @teddybear it worked! Also renaming the opencv_java4.so inside .aar file into opencv_java4100.so worked.
 
Upvote 0
Top