I want to cross compile a c++ library to the android plateform and this library depends on other libraries (those librairies are included yet in the android plateform).
Actually ,i have downloaded the android source code (android 4.1), i have also the library source code and i just don't know how to cross compile this library with it dependencies?
I would be thankfull if someone can tell me the right way to do it.
I believe that the easiest path is to set up the standalone toolchain using latest Android NDK, and build your library and all its dependencies with that toolchain. Here is an example: http://trac.osgeo.org/gdal/wiki/BuildingForAndroid
Related
I have editted parts of the zlib-1.2.13 library to add additional functionality.
I would like to compile this library and produce a static library that I can link to as part of an android app.
I am struggling to use CMAKE to compile the static library for the correct architecture.
My question is, how do I compile and generate a static library that I can link to as part of an android app?
I saw a similar question on here that led me to try compile the library using the following command, 'CC=gcc CHOST=arm64 ./configure', then 'sudo make' on my linux VM however the static library generated appears to still be for the linux architecture.
As well as this, when I try to run the CMAKE directly through android studio, pointing the build.gradle file directly at the zlib CMAKELists.txt file directly no libraries are generated.
Any help would be greatly appreciated! :)
I am working on an Android application with NDK. My c++ code has some dependencies from c++ open source libraries, so I can download the source code of the dependencies and package them in my app. I have created my CMakeList files, but I don't know how to include the external library.
I would like to build the dependency to be able to use it in my own project, so the flow would be as follows:
cd external/library/path
./configure
make
build my app and link the built dependency
Is this possible? If so, how can this be done? Sorry if this is a dumb question, I'm new on C++ and Cmake.
The way I solved this was by cross compiling the libraries and adding them as static libraries. You can cross compile using the clang binaries included in the ndk directory, using the one that targets your app min sdk.
Suppose I have prebuilt OpenCV Android native libraries, such as this. How to find which version of NDK is used for building this?
I am curios about this because OpenCV 3.4.3 prebuilt Android libraries seems to incompatible (?) with NDK r18.
OpenCV library contained this information. Open the prebuilt library in Notepad++ and search for "General configuration for OpenCV".
Assuming it was built with a new enough version of the NDK (I don't remember exactly when we added this, but it's been a year or two), there's an ELF note baked into the binaries. Can use https://android.googlesource.com/platform/ndk/+/master/parse_elfnote.py to parse it. It'll show you something like the following:
$ python parse_elfnote.py $NDK/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so
----------ABI INFO----------
ABI_ANDROID_API: 21
ABI_NDK_VERSION: r18
ABI_NDK_BUILD_NUMBER: 5002713
Is there any way to determine what version of the NDK was used to compile an "aar" library? Either decompiling, or via code would be fine, just need to know.
I am trying to determine what version of the ndk one of my third party libraries was built using.
An "aar" file is not compiled with NDK, you probably mean one of the c++ libraries inside that file. There is no simple way, but you can rule out new ndk versions according to the library date.
Also, you might be able to find out by getting the compiler version - see if something like this can help: How to retrieve the GCC version used to compile a given ELF executable
I have some C++ code (interacts with micro controllers) written already by someone else. I learnt android & NDK and comfortable writing small sample programs. Now I need to integrate both.
So, How should I start proceeding on the integration part? How does the NDK actually works? Assuming I have 3 parts now A - C++ code, B - NDK native interface code, C - Android Activity/Class .
1) Should I compile A (g++ linaro) and then place the object file in Android project to be called by C through B?
(or)
2) Should I compile the A & B together using g++ (linaro) and then copy the .so file into the Android Eclipse project? (Not sure how complex it will be to mimic NDK-build command in normal eclipse).
(or)
3) Copy A into Android Eclipse project and generate java.h file, then generate .so file using the both A & B. (In this method I need to find the right place to put the whole CPP project files in the Android/NDK eclipse project).
PS: I tried to find examples that does this, but only seem to find the simple basic examples, which I am pretty comfortable creating already. I need help in the integration part, please post me tutorial if you know (Android/NDK/Eclipse/already_existing_C++_code).
You should compile A using the Android toolchain. Note that Android supports not only ARM (a.k.a. armeabi) but also armv7a, x86, mips, and recently - armeabi-v7a-hard. Soon, x86-64 will be released.
You can compile A with Android standalone toolchain, no need to adopt the NDK build system.
You can compile B as part of A, or separately. In the latter case, simply load A before B in your Java static constructor:
{
loadLibrary("A");
loadLibrary("B");
}
because libB.so will have dependencies on libA.so.
You can pack both libA.so and libB.so in the APK (in folders libs/armeabi, libs/x86, etc.)
First of all, I recommend you to read Android NDK documents. Android.mk is not hard to write in order to compile C++ code into shared library for JNI using NDK toolchain. The most difficult part might be that Android libc (bionic) is not the same as ordinary Linux libc.
So, try to compile A - C++ code using NDK toolchain first. If you failed it, you should port it to Android libc, or you should compile it and link statically it using linaro toolchain. Take a look at the documents to link static elf library using NDK toolchain. But the binary wouldn't work on Linux because Android Linux kernel is not the same as linaro.
Anyway if you got to compile a shared library, easy to integrate it to Android project. just put the shared library to libs/[arch], like libs/armeabi-v7a/libfoo.so.