Big Bad Robots is an indie game developer but we also do contract development. We have developed on all kinds of platforms (PC,Handheld,Consoles) but now primarily focus on iOS,Android and Unity. Contact us if you looking for developers with over 20 years experience in software and game development at biz -at- bigbadrobots.com

Integrating C++ via the Android NDK.

November 16, 2009terence

I finally had enough time to look at developing on the Android platform and got my test integration of C++ code with the Android NDK working. The biggest hurdle proved to be familiarity with the Android development environment itself. The following tips apply to NDK 1.6r1:

1) You DO NOT have to have surround your functions with a various extern “C”‘s. Unlike what people are saying out there about having to do it you do not have to do it.

2) Check the names of the class to make sure the packages match your JNI interface. (i.e. if your class with the native interfaces are com.examples.HelloWorld…..your JNI class should be Java_com_examples_HelloWorld_<class>

3) Check your android.xml file for the proper package export. When you refactor/rename things in the Eclipse editor it will not update the package export. This will result in Android not being able to find your JNI interface and complain in logcat.

As of 1.6r1, the NDK is something still to play around with and not really ready for production development. That seems to be way the Google Android teams seems to like to run things. Although the OpenGL ES 1.0 libs are available, other supporting libraries are not (i.e. those to load png or jpg’s for texture. The audio libraries). My initial experiments on writing xPhone with Android has a initial platform would prove daunting to say the least.

3 responses to “Integrating C++ via the Android NDK.”

  1. wktang says:

    It would be a dream to be able to build a framework that is able to compile the same code on both platforms (iPhone and Android).

    I wonder if you have watched this video presentation (Link below) by one of the developers of Mytopia, which they build an online social game on multiple platforms such as Facebook, Friendster, Android, iPhone, Symbian and others…


    Google just announced Nexus One phone to compete with the iPhone. It would be really interesting this year to see how smartphones progress to be the next generation pocket computers.

  2. Tony Hartley says:

    Hi Terence,

    We’ve just released MoSync Android C/C++ SDK, so now its possible to program Android in C++ without the hassle of using the NDK, no more messing around with interfacing to Java.

    We are an open source project, so we would really appreciate all the feedback you can give us.

    You can get it at mosync.com



  3. bowerymarc says:

    “1) You DO NOT have to have surround your functions with a various extern ā€œCā€ā€˜s. Unlike what people are saying out there about having to do it you do not have to do it.”

    actually yeah, if it’s a .cpp file you do, if it’s a .c you don’t. all you gotta do is *try* it and you’ll see šŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *