Yang Huang Port iphone cocos2d-x game to android
Posts 11
Added by Yang Huang almost 2 years ago

Hi all,

I am trying to port an iphone cocos2d-x game to android. But I got a few issues.
1) When I try to run the build_native.sh, the compiler seems not support the try...catch... block in the cpp source file. But it can compile when I set the APP_STL to gnustl_static in the Application.mk. But when I change to this, the complier stops due to some c function such as "strcmp" hasn't declare. (something about exception support in android ndk can be found here, http://stackoverflow.com/questions/4663291/android-ndk-r5-and-support-of-c-exception)

2) When I remove the try...catch... block in the cpp source code and use the APP_STL := stlport_static option. The compiler stops due to "isdigit()" hasn't declared in the scope. I found that the "isdigit()" function is declared in the /usr/include/ in the xcode reference. How can I let the compiler to search the /usr/include/ directory?

Thank you!

Zhe Wang RE: Port iphone cocos2d-x game to android
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

Sorry for the late reply.
Using try-catch is un-recommended on android ndk. As you seen, cocos2d-x isn't use it. Linking stlport is the right choice.

"isdigit(int)" is a method in standard C library, you can find it in android-ndk-r5/platforms/android-9/arch-arm/usr/include/ctype.h
ndk-build can find the ndk headers if you run the build commend at the root of android-ndk-r5

For example, your path is

/android-ndk-r5/
/MyProjects/MyGame/android/

Then you can run the build_native.sh in MyGame/android/ folder (don't forget to modify the XXX_ROOT params in it),
or manually run
pushd /android-ndk-r5/
./ndk-build -C /MyProject/MyGame/android/   // run ndk-build at the root of ndk
popd

Enjoy Coding, Enjoy Life.

Yang Huang RE: Port iphone cocos2d-x game to android
Posts 11
Added by Yang Huang almost 2 years ago

Thank Walzer!
Which version of android ndk do you recommend?
It seems that I can only download ndkr6 on the official android site.

Zhe Wang RE: Port iphone cocos2d-x game to android
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

I'm so lazy and using ndk-r5.
OK, Let me test 2d-x on ndk-r6, I'm downloading it now.

Enjoy Coding, Enjoy Life.

Yang Huang RE: Port iphone cocos2d-x game to android
Posts 11
Added by Yang Huang almost 2 years ago

Thank you!:)


(1-4/4)