I am trying to use SQLCipher within Android. They made it very easy to integrate by adding the dependency:
implementation 'net.zetetic:android-database-sqlcipher:4.2.0#aar'
They have nice and simple examples of then using this in Java, but my application is c++ and I am using the NDK. SQLCipher is primarily C code so I know that this is linking against some compiled C code. Are the headers available for use? Where are these dependencies being installed. I am an iOS developer new to Android so I feel like this should simple but I am just missing something.
There's currently no support for consuming C/C++ dependencies from an AAR. We're working on this here: https://github.com/android-ndk/ndk/issues/916
But I should note that even when that is complete, sqlcipher does need to choose to expose that library. The AAR would not currently contain includes, and it may not be a stable API so they may choose not to expose it.
For a library to be usable directly by ndk, you'd need a .so version of it to link against. If you're including the library like this, you'd use JNI to access it via Java.
I'd recommend against hacking something up to access their .so files directly. Its quite possible their Java code has business logic that prevents errors or initialized things that are not set up properly if you go right against their .so file.
Related
We use Xamarin Forms and I have been tasked with integrating a 3rd party AAR library from a business partner and I don't have control over the library or its dependencies. This library itself is distributed using Maven, which works great in Android Studio but is a pain in Xamarin, and it has many dependencies on both libraries that are standard in Android as well as other proprietary libraries.
Since I only need to interact with a small portion of the public API of the main library, I've created an Android library (AAR) wrapper project in Android Studio that only exposes the functionality I need and does not use any types that do not already have bindings.
I have created an Android binding project against the AAR wrapper library, and it compiles in Visual Studio without any warnings or errors.
I've created bindings for other libraries in the past and have the Xamarin binding documentation multiple times and searched online, but the part I'm missing is how to include the required/reference JAR/AAR files in the compilation process and the final Android application. Most of the standard libraries that I need already have NuGet packages (Androidx, Google Play Services, etc)., but the binding library compiles without complaint - so how do I include the other required libraries?
Do I really have to create a binding project for each required AAR/JAR and add as a reference? I don't need to interact with the types or resources in these libraries directly from Xamarin since I only interact with the the types/methods exposed in the wrapper AAR (e.g. I don't think I really need a Xamarin binding). Is there a way to simply have Xamarin process the required AARs and JARs without creating a Xamarin binding project for every library that doesn't already have a NuGet package? There are many many dependencies which makes this theoretically possible, but not in practice. There must be an easier way...
I noticed there is an AndroidLibrary build action that the documentation says can be used to directly reference an AAR/JAR file in a Android application, but I can find no examples of how to use this in practice. What does this build action do? How is it supposed to be used? https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-items#androidaarlibrary
Thanks in advance for any help or direction on the best way to do this.
I have looked at Use prebuilt JNI library in Android Studio 3.1 and How to use .so in a second project in Android?. The first is trying to get a library file without headers working and the other seems to be focusing on a specific issue with his build (although there's some useful information there). I'm relatively new to app development and especially to native development on android. I've gotten a build with the JNI library and some c++ code working, but that seems to be just for building from source.
It's probably a simple answer, but I haven't been able to find documentation on this specifically in the android developers documentation. I'm interested in understanding the correct (or most conventional) place to put and way to use a precompiled library (module/lib/*.so and module/include/*.h) in an android project. Would I even need to use JNI or the NDK if the library is built with another build tool? Another project I have has a native library source object (*.so) in ./obj/local, ./libs, and in many other folders related to JNI. I'm guessing it would be somewhere in there, but I'd like to know what is conventional.
For some context, I'm trying to work with the essentia library. I have followed the guide on compiling for Android and have a build with the general hierarchy mentioned above (essentia/lib and essentia/include) that seems to be working.
I've been developing a library to use in my project, and while it is working locally, I would like to share it and use it as an external dependency.
How do I wrap my library so that built AAR contains both *.so native library and generated *.java classes (generated by Kotlin compiler) ? Because there are two-way interactions in my library: Kotlin external functions defined in C++, and some C++ code calling Kotlin classes and methods.
So, my questions are:
How to correctly package Kotlin + JNI android library ?
How to upload said package to Bintray so users (and myself) could use it as a dependency ?
(Note: I've seen tutorials and examples, but they were either Kotlin/Android or Java/Jni/Android)
If you want to package .so with your application, note that you can always put it inside JAR file. Then, you can unpack it, and load it using System.load.
You can find sample here: https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031
Note
Remember that packaging .so inside application is a risky thing. As you deal with native code, you have to be 100% sure that all native dependencies are there. You have to pay attention to architecture as well.
I am currently working on an android project that requires me to make use of functions included in a shared library (.so). I also only have header (.h) files for the library provided to me.
Is it possible to work with just these two files? Or do I need to create my own implemenations via c++ codes?
I am using Android Studio intend to use CMake.
Regards,
Philip
Most Android apps are written in Java. Google has released the Native Developer Kit (NDK) in order to allow developers to write libraries in C++. However, these libraries are usually very low level and called from the Java code which defines the UI and higher-level app logic. Most likely you will need to write a wrapper for the library so that you can call it from Java code. Looks like this blog is a good place to start.
So, I have a little C library. I want to make this library available to other devs that develop native C code in android (other libraries, native apps etc).
What's the best way to go? I don't really have much clue yet, trying to figure all this out.
I've read that there are two paths to go with the NDK: using Android.mk and using create-standalone-toolchain -- is this correct? How does each one of these works? Is there a third way without the NDK, and should this be used now that the NDK is available?
**
This may have been asked before, but I understand things have changed since the release of the NDK, as a lot of posts I find seem obsolete.
this question can have a Huge answer, I will try to be as brief as possible.
Using the Android NDK, make a new android project, create a JNI folder, and create an Android.mk file, in it, make two libs, one being your lib, exported as a shared lib and the other, a jniwrapper that will test it. Here is an example of how it was done by a guy for his own lib.
You can make a shared lib by compiling with the standalone toolchain, here is an article on the subject and also take a look at the curl Readme for android, it explains how to compile curl for Android using the standalone toolchain, I believe it's the better way to do it, and also to easier for you since you will use the cross-compiler in a regular fasion...