Android has a native development kit (NDK) which can be used to create JNI native code for Android applications. In this video, I show how I convert an Android project in Eclipse to add the C/C++ nature to it and set it up to build the shared library that gets included in your Android apk file. This gives you all the power of the CDT in combination with the JDT to build Android apps with native code. Except for debug, though, as JNI debug remains the lost holy grail for the CDT...
If you want to look at the code from the demo, you can clone or download from http://github.com/dschaefer/androidDemo.
Link to YouTube
thanks for the demo!!!
ReplyDeleteWow, I never though Eclipse is capable of such things :)
ReplyDeleteI'm using Visual Studio + links inplace of real folders in NDK, so all source code and output is in fact in my Java project. But building is cumbersome - I have to issue make APP command in cygwin window.
This was a great demo and I'm using this combined java/C++ eclipse view. However, sometimes (like right now) the .apk file won't rebuild and I can't seem to force it. Cleaning the project only rebuilds the C/C++ and the .class files but the .apk and .dex files remain untouched.
ReplyDeleteHi Doug!
ReplyDeleteI read your article and found it very interesting, thank you very much!
Just one question, I'm trying to use this lib (http://github.com/billmccord/OpenCV-Android) for android but I can't get it to work right.
Could you give me a hand on that?
Thanks buddy!
This the only article I found about AndroidNDK & CDT. Thanks for that !
ReplyDeleteThe only thing I changed is the makefile to make it directory-recursive.
For those (like me) who aren't friendly with makefiles :
Add this :
# Find all subfolders of native folder
SRC_DIRS = $(shell find native -type d -print)
And replace this :
# Find all the C++ sources in the source folders
SOURCES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.cpp))
Thanks again
There is no C/C++ perspective in Eclipse for me, and there is no CDT builder either. Do I need to a plugin to do this in Eclipse?
ReplyDeletethank you soooo much. Had to tart around with it for a while but got there in the end
ReplyDeleteYou Sir are a Legend.
ReplyDeleteThanks for sharing this.
Dave.
This comment has been removed by the author.
ReplyDeleteI get the error jni.h no such file or directory, and i add include file into makefile as:
ReplyDelete-I$(ANDROID_NDK_BASE)/build/platforms/android-1.5/arch-arm/usr/include \
-I"C:/Program Files (x86)/Java/jdk1.6.0_22/include" \
-I"C:/Program Files (x86)/Java/jdk1.6.0_22/include/win32"
i also get a bunch of error according jni.h.
How to solve this path problem.
Hi Doug,
ReplyDeleteIs debugging tool available now for Eclipse CDT? thanks
Rave
Hey Doug!
ReplyDeleteI'd like to say a massive massive thank you for that makefile! I just modified yours to point to the Mac directories and it worked :) It has saved me hours or trawling through the docs and allowed me to study it and work out what is going on!
Thanks again!
Dan :)
Hi,
ReplyDeleteI don´t if it is not off topic, but nowadays the new way exists. The eclipse offers Sequoyah module which enables native and java coding together. The good tutorial is placed here - http://www.permadi.com/blog/2011/09/setting-up-android-jni-projects-in-windows-eclipse-and-sequoyah/
Hope this will help.