"The topic of .so files has come up many times, and I need to ask about it again. I’m not very familiar with them, so I have a question: how do I add a .so library in an Android build?
No matter how I try, I can’t access the methods from the .so file.
Also, wherever I add it to the .apk, ‘_test.so’ is appended to the file name.
unpacked aar
A shared object file is loaded and used at runtime by the main application. You usually include .so files in your final application bundle from a Gradle dependency with an .aar file containing .so files:
When you bundle for Android and you have a dependency which includes a /jni folder with .so files we get them from the build server and include them in your .aab/.apk file. In .aab files the .so files are stored in /base/lib/PLATFORM/foobar.so:
You should be able to manually include .so files like you did by putting them in your extension in /res/android …
yes! now it builds, and i can operate with code from Java side, but if i try to call same methods from C++, i got error
2024-08-27 12:37:12.762 7166-7204 om.example.todo com.example.todo A java_vm_ext.cc:591] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "gadsme.support.resource.Resource" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]
java_vm_ext.cc:591] at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:259)
java_vm_ext.cc:591] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
java_vm_ext.cc:591] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
java_vm_ext.cc:591]
java_vm_ext.cc:591] in call to NewGlobalRef
but class gadsme.support.resource.Resource is already in dex file
So you are able to call the function in the library? But it crashes after a while? I’m curious to learn what the Android device log says. Have you looked for clues as to why it crashes?
textava_vm_ext.cc:591] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "gadsme.support.resource.Resource" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]
java_vm_ext.cc:591] at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:259)
java_vm_ext.cc:591] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
java_vm_ext.cc:591] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
java_vm_ext.cc:591]
java_vm_ext.cc:591] in call to NewGlobalRef