I have created a new HELLOWORLD project with cocos2dX v3.9, NDK r9d, cocos console; by using cocos console compile method in terminal (MAC), it can produce the apk and install and run on a android device. The iOS part can be run on Xcode with no problems too.
Then I have created a SpriteExt class which just extends Sprite class (and do nothing else).
SpriteExt.h
#ifndef __TestProject__SpriteExt__
#define __TestProject__SpriteExt__
#include <iostream>
#include "cocos2d.h"
USING_NS_CC;
class SpriteExt: public Sprite {
public:
SpriteExt(void);
virtual ~SpriteExt();
static SpriteExt* create(std::string filename);
};
#endif /* defined(__TestProject__SpriteExt__) */
SpriteExt.cpp
#include "SpriteExt.h"
SpriteExt::SpriteExt(void) {
}
SpriteExt::~SpriteExt(void) {
}
SpriteExt* SpriteExt::create(std::string filename) {
SpriteExt* pS=new SpriteExt();
pS->initWithFile(filename);
pS->autorelease();
return pS;
}
I used it to replace the cocos2dx icon sprite class, it works correctly on iOS, but I cannot build the apk for android anymore.
helloworld.cpp:
SpriteExt *sprite = SpriteExt::create("HelloWorld.png");
Here’s the error I got on terminal:
.
.
.
[armeabi] StaticLibrary : libcpufeatures.a
[armeabi] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[armeabi] SharedLibrary : libcocos2dcpp.so
jni/../../Classes/HelloWorldScene.cpp:72: error: undefined reference to 'SpriteExt::create(std::string)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
make: Leaving directory `/Users/kitdashxt/Desktop/TestProject/proj.android'
Error running command, return code: 2.
tried to remove all folders in proj.android except jni, res and src to force terminal to rebuild it from scratch but it still didn’t work.
Anyone any tips/hints would be appreciated!
Thank you in advanced.