I am trying to build a native daemon on Android. The purpose to to control some specific hardware, and Java applications will be able to communicate to this daemon using sockets.
I have been using cmake meanwhile to compile my libraries, demos and the real daemon (which works fine BTW). I am now trying to do 2 different things:
- Build the same apps using
ndk-build. - Port the C++ daemon to an Android service, by making JNI calls very similar to the way the c++ daemon works.
As far as I understand, ndk-build cannot make native applications, but only native libraries, which in turn can be loaded by the Java GUI… am I correct? For step1 I don’t really need java (and I have proven it already), but I have yet found a way for ndk-build to spit an elf application.
For reference – I am using cmake, as described here: http://opekar.blogspot.com/2011/06/android-cmake-is-much-easier-in-ndk-r5b.html
This way I can have builds for “normal” linux, and also android using out of source builds. Quite nice hack if you ask me.
As mentioned by @Mārtiņš Možeik in one of the comments, this pice of
Android.mkwill work:One thing I do notice is that the binary produced by this “makefile” is 130k, while the binary produced by cmake was ~40 kb. This is because I used
-sas aC_FLAGand then gcc will strip the produced object on the fly. This can be done later on by calling$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-stripor the corresponding strip for your arch.As I have not found documentation of this feature on the internet, some more words:
jni/Android.mk.jnidirectory this get ugly, but not impossible. You just need to prefix the code with the corresponding prefixes, don’t forget to modify also the include path. This is left to the reader as an exercise.cmake. I previously said thatstripis not called – but it is called before the *.so are copied to thelibdirectory.execvps the daemon.