Thursday, September 10, 2009

Using CDT for Android Native

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

13 comments:

  1. thanks for the demo!!!

    ReplyDelete
  2. Wow, I never though Eclipse is capable of such things :)
    I'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.

    ReplyDelete
  3. 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.

    ReplyDelete
  4. Hi Doug!

    I 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!

    ReplyDelete
  5. This the only article I found about AndroidNDK & CDT. Thanks for that !

    The 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

    ReplyDelete
  6. 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?

    ReplyDelete
  7. thank you soooo much. Had to tart around with it for a while but got there in the end

    ReplyDelete
  8. You Sir are a Legend.
    Thanks for sharing this.

    Dave.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. I get the error jni.h no such file or directory, and i add include file into makefile as:
    -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.

    ReplyDelete
  11. Hi Doug,

    Is debugging tool available now for Eclipse CDT? thanks

    Rave

    ReplyDelete
  12. Hey Doug!

    I'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 :)

    ReplyDelete
  13. Hi,

    I 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.

    ReplyDelete