I've written a basic game using Cocos2D-x on XCode. It works fine on the iPhone. Now I'm trying to port it to Android. When I run the script ./build_native.sh inside the proj.android folder, it gives me the following error:

jni/../../Classes/MemoryModeLayer.cpp: In member function 'void MemoryModeLayer::startNewGame()':
jni/../../Classes/MemoryModeLayer.cpp:109:25: error: 'time' is not a member of 'std'
jni/../../Classes/MemoryModeLayer.cpp:109:25: note: suggested alternative:
/Users/abc/android-ndk-r9d/platforms/android-8/arch-arm/usr/include/time.h:40:17: note:   'time'
jni/../../Classes/MemoryModeLayer.cpp:111:5: error: 'random_shuffle' is not a member of 'std'
jni/../../Classes/MemoryModeLayer.cpp:112:5: error: 'random_shuffle' is not a member of 'std'
make: *** [obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/MemoryModeLayer.o] Error 1
make: Leaving directory `/Users/abc/cocos2d-x-2.2.3/projects/Game/proj.android'

In MemoryModeLayer.cpp I have the following:

std::random_shuffle(_xCod, _xCod + _numberOfRows);
std::random_shuffle(_yCod, _yCod + _numberOfColumns);

I've included the following headers as well:

#include <string>
#include <ctime>
#include <algorithm> 
#include <iostream>
#include <iomanip>

Also added using namespace std in the header file. Is there anything else that I should do?


There was a problem with the Application.mk file. Had to change the STL library lookup like so:

Add APP_STL := stlport_static to the Application.mk file. It may already have APP_STL := gnustl_static.

This blog post was very helpful!



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.