Are there any libraries available by default in the Android NDK? If not, can I use any c++/c library, as long as I include it myself?
In particular, I need compression, encryption, regex and sqlite. I was thinking of using zlib, crypto++, sqlite(duh!) and boost, but can use anything else if it is already available.
Also, if nothing is available built-in, would you recommend something other then my above choice (I prefer public-domain when possible, or BSD or similar)
SQLite is available on Android via abstracted database access in Java. The .so itself is private. You can of course compile your own SQLite library if you require modifications, but in general you should access it from Java. I have done this for encryption purposes.
zlib is available to the NDK
crypto++ could of course be compiled via the NDK
Boost certainly works on Android/NDK (I'm currently using it heavily)
By default Android NDK delivers some libraries, so called 'stable native APIs' (http://developer.android.com/sdk/ndk/overview.html):
libc (C library) headers
libm (math library) headers
JNI interface headers
libz (Zlib compression) headers
liblog (Android logging) header
OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
A Minimal set of headers for C++ support
OpenSL ES native audio libraries
Android native application APIS
First, I think you need to download the NDK package from here: http://developer.android.com/sdk/ndk/index.html and investigate the documentation from the package. I'm sure you will get the answers to most of your questions.
And quick answer to your questions. Yes there are libraries by default in the Android NDK. For example standard C and C++ libraries.
This is only a partial answer with respect to Crypto++....
Crypto++ has a wiki page with build instructions from the command line at Android (Command Line). The process will create the various libraries and show you how to build cryptest.exe to verify the library on a device. But you will still need to create you wrapper project using Android's build system.
Piotr Morgwai Kotarbiński has a page on building the Crypto++ library with Android's modified build system. See Building Crypto++ with NDK toolchain. I don't believe Piotr's article verifies the library on a device.
Related
I am compiling a c++ library to be used on my Android device.
In compiling the library I did not take into account the architecture I was building the library for.
As a result I have a 64 bit dynamically linked shared library x86_64 which only works on 64 bit systems.
I intend to link this library to my android device using the JNA tool.
What is the appropriate way to compile my c++ library for android architecture and JNA.
You must use the Android NDK.
Depending on the target architecture, you must select the appropriate toolchain/cross-compiler, e.g. ARM, MIPS or x86.
See also Getting Started with the NDK
JNI or JNA have nothing to do with how the library is built. You must build the library for your target architecture, so it can be used on your phone or tablet.
To access this library from Java, you may use either JNI or JNA.
With JNI, you must implement glue code in C/C++. With JNA on the other side, you do more or less the same, but you use an existing library (libffi) and implement the glue code in Java. This is done dynamically at runtime and may be thought of something like reflection for a library.
I am building a multi-platform SDK for real time 3D applications. This SDK is programmed in C++ and works under Windows, Apple's iOs, MacOS, Linux and Android.
The project structure is complex, it consists in 3 native C++ static libraries, linked with some external static libraries in a complete shared library. This is very simple under all the managed OSes, except for Android.
The major problem in Android is bi-directional communication/calls between native code and Java code. I got this solved some time ago using SWIG to wrap the shared library's classes. To achieve that I wrote our my own build scripts (Makefiles) to handle native compilation with the ndk r4, swig code generation, java pre-compilation and jar creation.
Lately we added some callback/listener classes in the C++ layer, that we wanted to be derivable/overloadable in Java, for this we used SWIG's directors feature. But it appears that it needs JNI features (weak global references) that were not in the NDK r4b. So we need to switch to a newer Android NDK (r6b) that has these features. But since our custom build scripts were written for NDK r4b they won't work anymore.
My concern is to have everything built properly through Android's NDK/SDK (eventually through Eclipse) with Android.mk files so we don't have to rewrite everything from scratch each time we switch to a new NDK.
I'd like to know if there is a way to manage such complex project structure with standard Android.mk, ndk-build, ant and eclipse (including the SWIG part). And if so, how ?
Don't hesitate to ask for precisions, I am not sure I am being really clear.
Any help greatly appreciated.
Florent Lagaye.
I've been looking for a similar thing and, although I haven't figured it out yet, there is a good example with building gstreamer on Android.
http://cgit.collabora.com/git/user/derek/androgenizer.git/
It supposedly works with any libtoolized application.
Here is the directions for how to build:
http://gstreamer.freedesktop.org/wiki/GstreamerAndroid_InstallInstructions
What we ended doing is writing specific rules in the Android.mk file to manage swig interface generation.
Remember to add the generated c++ source to the list of source files before including BUILD_STATIC_LIB or BUILD_DYNAMIC_LIB, and to instruct swig to generate the java source in folder accessible by your Android java project.
Hey guys!
I've been working on c++ application lately which has to be run on Android 2.1 and 2.2.
so I am wondering if I have complete c++ application can I just put it into *.so file and then create android project and just simply load this library using System.loadLibrary(blalba.so);
would it work?
Yes you will have to recompile all the native libraries specifically for Android. Yes, you do need the source code for all 3rd party native libs you plan to use simply because Usually when we compile and link these libraries outside Android they are linked to glibc but unfortunately Android doesn't use glibc due to liscence and performance issues. Android uses a watered down version of glibc called libc. It has matching symbol names to glibc for most of the usual functionalities. But as far as i know the libc doesn't have some functionality related to Strings and it definitely doesnt have some posix support. If your native libraries are using any of the deprecated functionality you will have to find workaround for those by using alternative functionality supported by libc and coding your libs accordingly.
Also, as you righty pointed out you will have to use the NDK to interface Java(Android app/fwk) to native world(C++).
Though this sounds pretty simple in my experience compiling native libraries on Android(Android porting) has traditionally been very time consuming with no guarantee of sucesses.
I would like to create a zip file from files located on the sd card, I have managed to do that using java but I think that the result is too slow, so I thought of going native using the android NDK.
My questions are:
Does anyone know any C/C++ library to zip unzip files that will work on android?
How to know if the library will work on android?
Will this make any difference on performance?
With regard to your question "How to know if the library will work on Android" - it depends on the dependencies that the library has. The standard google NDK has very limited C++ support. If it's written in C you're probably OK, but if it's C++ you need to make sure it uses ONLY the following headers/libraries:
libc (C library) headers
libm (math library) headers
JNI interface headers
libz (Zlib compression) headers
liblog (Android logging) header
OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
A Minimal set of headers for C++ support
(From homepage)
If you need full C++ support, you will need to use the Crystax NDK.
Be forewarned - the process of cross compilation is Very. Complicated. If you're not extremely comfortable on the command line and with the ins and outs of C compilation, linking, etc., I would look for an alternative solution.
I personally like 7zip, they are open sourced here. You can try compiling this within your app in Android NDK. gzip is also another good option.
Given how core zip files (apk files, jar files) are to android, I'd be very surprised if the java zip file functions aren't using native implementations of the actual algorithms.
Remember the SD card itself is slow compared to ordinary disks.
Is there any info about the future of extending the safe C++ header list in the NDK (or maybe some hints to what might be safe to use) ? Or how soon we can expect the next NDK update? Also will there be any tutorials and documentation comming out for the NDK?
Thanks
If you are interested in using C++ with the Android NDK you should check out the modified NDK by CrystaX. He has rebuilt the Android NDK so that it has full support for C++, including C++ Exceptions, RTTI (Run Time Type Identification) and the Standard C++ Library.
There aren't that many changes, in fact CrystaX offers a link to the complete patch file from his website.
Check it out at http://www.crystax.net/android/ndk-r4.php
i'm not aware of any announcements regarding future plans.
the samples are here:
http://developer.android.com/sdk/ndk/1.6_r1/index.html#samples
and the NDK itself contains documentation in the form of .txt files in the docs/ directory.