[solved] Error when building in android studio

I get error when using command prompt to compile

cocos compile -p android -ap android-19
jni/../../Classes/AppDelegate.cpp:104: error: undefined reference to 'BattleScene::createScene()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
make.exe: Leaving directory `D:/CombatBot/proj.android'
Error running command, return code: 2.

even tho I properly added the references in Android.mk like

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   ../../../Classes/AIClass.cpp \
                   ../../../Classes/BattleScene.cpp \
                   ../../../Classes/MainMenu.cpp \
                   ../../../Classes/Modules.cpp \
                   ../../../Classes/ProjectileTemplate.cpp \
                   ../../../Classes/RobotTemplate.cpp

this.
I use ndk r10c, set my sdk build 19, and using Android Studio.
Even smallest clues are appreciated. I can provide more info if needed.

It’s probably a coding error. Could you post some code? BattleScene.cpp and .h and your AppDelegate call to ‘BattleScene::createScene()’

Also, what Android.mk file are you editing? The one in proj.android or the one in proj.android-studio?

Is createScene() public and static?

Scene* BattleScene::createScene()
{
	// 'scene' is an autorelease object
	auto scene = Scene::create();

	// 'layer' is an autorelease object
	auto layer = BattleScene::create();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

same as the one created default, so I don’t think it has any problem.
and yes it is public and static

public:
	static cocos2d::Scene* createScene();

I was able to build apk with different command

cocos compile -p android --android-studio --api-abi x86 

but when I run it, nothing but black screen
btw the game runs fine on VS.

I am editing the one in proj.android-studio

When compiling without --android-studio tag you are compiling the project inside proj.android, not proj.android-studio. That’s why you were getting that error, because you probably didn’t add your files to the Android.mk inside proj.android.

1 Like

Thank you for the reply.
I was able to compile without error, but as I try to run it, nothing shows up.
I think I am missing something. I should try to re-set up the environment.

Anyone know good tutorial I can follow?

Do you know if you have a runtime error or not? Did you check the logcat?

I can’t check it at the moment. I have usb connection problem so I manually move the apk file to the device to install and test. It doesn’t crash, just black screen.

Well in that case I don’t see something obvious that you are missing. You should try resolving your usb connection problem and check your log. Maybe try creating a new project and moving your existing sources and resources there…

1 Like

I built new project and moved all my codes to there,
checked logcat and found one spelling error which caused libcocos2dx to stop
I will work with new project folder from now on. Thx for all the replies!