I am building an open source lib C/C++ for Android development using Android NDK. I had got code from Github and created my own jni folder under source code. In that jni folder, I created some C source files and included many header files in open source lib. But when I built, I had got failed log:
fatal error: bits/libc-header-start.h: No such file or directory
I checked and saw that file "libc-header-start.h" existed in /usr/include/x86_64-linux-gnu/bits/ folder of Ubuntu system but when building, it can not link to that header file
So can I use Ubuntu system header file in my Android NDK lib?
No, you should not use Ubuntu (or any other host) includes or libs to build an Android NDK library. NDK cross-compiles your code for the Android targets. Not all C++ projects on GitHub may be ported easily to Android. If they use CMake, these scripts often need adaptations for Android NDK. If they use automake tools, tuning the build scripts may be quite painful.
So can I use Ubuntu system header file in my Android NDK lib?
NO. You have to use all the Android NDK specific headers and libs for your NDK compilation, i.e. those inside your NDK folders.
Here is an example for Android JNI programming: https://github.com/russell-shizhen/JniExample
Related
I have a lib and dll files (I can choose which file I want to use)
I want to call to functions that are inside the file.
The code that complied in dll/lib wrote at c
dll files (unless the dll is a dot.net dll and you are in a Xamarin app) are not usable in Android.
Furthermore DLL files typically are compiled for x86 (32bit) or x86_64 (64bit) CPUs. The number of Andorid devices with an x86 CPU is next to zero, for Android you need the library compiled for ARMv7 (32bit) and ARMv8 (64bit). As Android is Linux based you need .so files in stead of .dll files.
To make development easier you should install Android Studio + Android NDK (Native Development Kit). Then you have everything for compiling c code in a way that you can make use of it within an Android app.
Google provides multiple sample projects that show how to use NDK: https://developer.android.com/ndk/samples
I am trying to build a .so for android and I want to build with address sanitizer but the only instructions I see are for Android NDK based Makefiles, but I am using the newer endorsed CMake setup. Just adding the flag -fsanitize=address wasn't enough as the clang runtime library was missing.
what is the correct thing to add in my CMakeLists for Android built libraries?
You also need to prepare your device as described in documentation. You have to run asan_device_setup script from NDK. It will put asan .so on the device.
First step: I use QtCreator to compile a bunch of libraries (.so files) + a GUI test program to test those libraries on an Android device.
Second step: After I tested them, I re-compile the libraries without the GUI test program and send them to a client who's going to integrate those .so file in its own Andoid application (generating and apk), not using QtCreator anymore. I do this step using QtCreator (because it's setup, very easy for me to just remove the GUI test program and hit compile), but I'm pretty sure they could also be compiled directly using ndk-build if I work on writting the correct make files for that.
When I re-compile the libraries, there's still a "Android build SDK" option under "Build Android APK" set to "android-22" in QtCreator. However, my client generates its final app for "android-19". And we are wondering if this could be a problem.
My understanding is that my .so files generated in "second step" are built using the NDK only (SDK is not used, so android API version "android-22" is irrelevant as I do not generate any APK...). So there should be no compatibility issue when those .so files are integrated in an application, as far as the same NDK version is used.
Am I right?
I have gone through this opencv Android samples link. In this link all the projects has a JNI C++ code which builds the ".so" file automatically and build the project. I need to create a sample project like the above examples, in which the C++ code builds automatically.
I have gone through few tutorials like this, which has steps to build JNI using command line but there is no steps to build it automatically/using eclipse project.
Can any one list out the steps to create a project in eclipse that builds JNI C++ files automatically?
I suggest you can read the article Getting Started with JNI on Android, Windows and Mac. You just need to right-click on your project and select Add Native Support. Then the IDE will automatically build the .so when you save all changes.
I have a Linux library that needs to be compiled under Android. I understand that should be used to build this program: / home/user/android-ndk/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc and then compile a ndk-build . I think right? Assembly via the utility should work correctly?
You need to install the Native Development Kit (NDK) and read through the documentation in the NDK about the build process. The NDK basic info is at http://developer.android.com/sdk/ndk/index.html, and you'll need to install an appropriate version of Cygwin (if you're using Windows).
It comes with a prebuilt compiler, so you shouldn't have to rebuild that.