Can I run cocos2d-x project on android-ndk r7?

Can I run cocos2d-x project on android-ndk r7?
0.0 0


I am very new to android development and cocos2d-x. I noticed that the document says it has to be ndk r4 or r5. but I could not get r4 or r5 compile. I got the error message says:

android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ar: No such file or directory

But I can get it compile for ndk r7. But the problem I have is the when I run it, the program just crashes and exit when I touch the screen.

If I just run a sprite even with animation it works fine with out the exit menu.

but If I add the exit menu that comes with the example, anywhere I touch the screen, the program just exit.

if I enable the touch and try to touch the sprite on the screen, the program just crashes and exit.

bool HelloWorld::init()
    bool bRet = false;
    do {
        // 1. super init first
//        if ( !CCLayer::init() )
  //      {
    //        return false;
      //  }
        CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)));
        // 2. add a menu item with "X" image, which is clicked to quit the program
        //    you may modify it.
        // add a "close" icon to exit the progress. it's an autorelease object
        CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
                                                                           menu_selector(HelloWorld::menuCloseCallback) );

        pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

        // create menu, it's an autorelease object
        CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
        pMenu->setPosition( CCPointZero );
        this->addChild(pMenu, 1);
        // 3. add your codes below...

        // add a label shows "Hello World"
        // create and initialize a label
        CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello from AbiTalk", "Arial", 24);
        // ask director the window size
        CCSize size = CCDirector::sharedDirector()->getWinSize();

        // position the label on the center of the screen
        pLabel->setPosition( ccp(size.width / 2, size.height - 50) );

        // add the label as a child to this layer
        this->addChild(pLabel, 1);


        CCAnimation* animation = CCAnimation::animation();
        char frameName[64];
        for(int i = 0; i < 10; i++) {
            sprintf(frameName, "bee%d.png", i); 
            CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName);
        CCAnimate *animate = CCAnimate::actionWithAnimation(animation,true);
        CCAction *act = CCRepeatForever::actionWithAction(animate);
        // add "HelloWorld" splash screen"
        CCSprite *obj  = CCSprite::spriteWithFile("bee0.png");

        // position the sprite on the center of the screen
        obj->setPosition( ccp(size.width/2, size.height/2) );
        // add the sprite as a child to this layer
        this->addChild(obj, 0);
        bRet = true;

        CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("backgroundmusic.mp3", true);

    } while (0);

    return bRet;
void HelloWorld::registerWithTouchDispatcher()
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event)
    CCPoint touchLocation = touch->locationInView( touch->view() );    
    touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );

    if (CCRect::CCRectContainsPoint(obj->boundingBox(), touchLocation))
    {// touch b sprite
        m_bSpritePressed = true;

    return true;

cocos2d-x Touch Even crashes

Could you attach a zip ball of your project in the post, so I can reproduce your crash? BTW, which type of device are you using, and what’s its sdk version?


Why should you implements registerWithTouchDispatcher in HelloWorld?


Hi Minggo Zhang: I do not know. I just use the same method in cocos2d-iphone. That is how they handle the touch event, you must have registerWithTouchDispatcher first. I am very new to cocos2d-x and android. I had a lot of problems right now. I don’t even know how to get CCLog to print at eclipse console.


Did you create the new project by create-android-project.bat/
If so, may be you should change in APP_ROOT/android/jni.


APP_STL := stlport_static


APP_STL := gnustl_static

Hope this helps.


Yes. Minggo Zhang. I created the project using I did what you said to change the to APP_STL:=gnustl_static. That solved everything. My project works find now. Thank you


It solved my problem too!