Friday, August 1, 2014

Building a Cocos2D-X Android App

The steps here are generally correct though I had to work through some version-specific issues:
http://www.cocos2d-x.org/wiki/How_to_Build_an_Android_Project_with_Eclipse

The above link is for Cocos2D-X version 3.0 while I was using version 3.2.

Versions:

  • As for Eclipse & Android SDK it's the Android ADT 20140702 bundle
  • NDK r10
Issues:

The first issue I ran into was NDK_ROOT not found in the environment (even though it has been defined in .bash_profile). I hardcoded it into the build_native.py and it solved the problem.


NDK_ROOT="path_to_ndk"

The next issue is a CPP compile issue in the file "cocos2d/cocos/3d/CCBundleReader.cpp". I changed the return type in the header to "ssize_t" and it worked.


   /**
    * Returns the position of the file pointer.
    */
   ssize_t tell();

Lastly, the Java compiler was missing libcocos2dx.jar

I had to open the project at "cocos2d-x-3.2/cocos/platform/android/java", compile the library project and copy the libcocos2dx.jar from the "bin" folder to my project's "lib" folder.

Note: I later found out that this is because I imported the Android project only in Eclipse by selecting the Eclipse project file. If I were to select the project at the top-level folder instead, I would have been given the option of importing the libcocos2dx library as well. In which case the project would have compiled without the steps above.

After these I could build the app. The CPP compile error was a bit of a surprise thought. It shouldn't be happening.

No comments:

Post a Comment