I am trying to build multiple .so libraries which must be included as separate libraries in the APKs 'lib' folder. How do I accomplish that using cmake and gradle?
Related
I am trying to implement aes_ctr128_encrypt in android using BoringSSL as defined by google.
I built the application with CMAKE and Gninja by following the link
https://boringssl.googlesource.com/boringssl/+/master/BUILDING.md
Now I have crypto and ssl folders in the build folder but there is no AES definition in any of the files as AES.h was in the include folder in root directory.
Anyhow, The binaries thus generated with CMAKE are also giving .a files and not .so files. How can I use those .a files in my project to access the aes_ctr_128_encrypt?
I trying to build android application with some precompiled native libraries:
liba.so and libb.so.1.2.3
Libraries are placed into jniLibs subdirectory.
After building APK file, only liba.so included into it, but not libb.so.1.2.3.
Result is predictable. Application crashes at start.
What to do with build scripts to include all files from jniLibs into APK?
Due to the native library regex ^.+\\.so$ being used in the Android Gradle plugin, it is impossible to include anything other than .so files using the jniLibs folder. And even if you were to somehow add the library to the APK, the dynamic loader on Android is very limited and will most likely not be able to load them.
Your best bet is to remove the version altogether by renaming the library and changing its internal soname before linking against it.
Unfortunately I don't develop for Android anymore, so I can't test this, but I know Gradle and this might work for you. Looking at the Android DSL docs, you might be able to change the filtering on the jniLibs folder:
android {
sourceSets {
main {
jniLibs.filter.include("**/*")
}
}
}
Let me know if this works!
Just add the jniLibs folder in app/src/main and it will include the .so file in the apk.
/app/src/main/armeabi/*.so files
I have cross compiled the native code for different architectures for android and have its corresponding jni wrapper class working in android studio. Now I want to make it available as a library. I have two questions:
1)Can I just jar the .so file and jni files to make the library?(not .aar because my library contains only the pure java and native code, no android related stuff such as .xml,res,etc) If so what should be its structure?
2) If I cannot create .jar file, then all I am left with is creating the .aar file. That would include the use of android studio. Can I do it without the android studio?
Edit 1:
If I jar the files, then I don't want to extract .so and then use it. If I jar the files, then add it(the .jar) as a dependency in my project then it should automatically put .so into libs/jni folder in my apk so that jni can find it. Question is how do I do that?(if possible)
Fortunately found a way. As .aar is itself a simple zip file with structure as specified here. What I did is "jar" all the .class files (inside proper package folder) into classes.jar, created an empty folder "res", put all .so files in jni folder (with proper architecture) and made a simple AndroidManifest.xml containing basic tags. Then I jar them into file with extension .aar (like mylib.aar). I have tested it by copying .aar into another project's libs folder and putting a dependency on it in app's build.gradle( like compile(name:'mylib',ext:'aar')). And it works great.
I'm building a native C++ library for Android, for use with a Unity 3d project.
I want to build for arm and x86, so I set this in application.mk
APP_ABI := all
This gives me several seperate .so files. Unfortunately currently the way to include an native android library in a unity app is to add the library to the folder assets\Plugins\Android.
I can only put one file with the libraries name in that folder. So i can only have one of the .so files in there.
Is there any way of merging them into one file?
You can put multiple .so files, one for each architecture, into the Plugins/Assets folder, per the Unity documentation:
For specific Android platform (armv7, x86), the libraries (lib*.so) should be placed in the following:
Assets/Plugins/Android/libs/x86/
Assets/Plugins/Android/libs/armeabi-v7a/
Merging multiple architectures into a single .so can't be done on Linux.
That requires fat binrary support, and the FatELF project is now dead.
I have added a libs folder to my project root and the libs contain two jar files. When I compile the source, I get the APK created. When I unzip the APK, I cannot see the libs folder in it? Why this behavoir, as I believe libs should be bundled with APK?
When you include a jar then a relevant code from there gets transformed into bytecode the same as your own code and it all becomes a single dex file within apk.
It is native *.so libraries which you create in C/C++ with the NDK for your project they get bundled into your apk as *.so files. Because they are not in Java.
I believe all necessary classes are put in dex file(Dalvik VM executable).