Android-cocos2dx

Hello.
I am trying to compile cocos2dx code on android studio without android.mk file.
Is there any way to do so, because in cocos when we add new class then we have to ass it in android.mk file.
i dont want to do it again and again.

is there any way using which i can compile c++ code on android studio without android.mk file…???

Thank you.

I think you can not compile for android without android.mk file, but you can config that file to auto scan new files like this:

FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp) //find in Classes
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../../Classes/*/*.cpp) // find in Classes/sub1
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../../Classes/*/**/*.cpp) // find in Classes/sub1/sub2

LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
2 Likes

I wouldn’t use wildcards for the folders, because this way you can’t mix platform specific code within the classes folder.

I have around 5 inner folder in classes folder. do i need to define all folder…???

Yea, I can feel that pain. After switching to android studio a nightmare has begun. ALWAYS some problems with everything, pure crap overall. But anyway, I have to build for android platform…
In the Xcode it’s all so simple and nice as usually and just works. Drag&drop files and compile them in no time.

Trying to use your solution, but without wildcard doesn’t work. How to make it happen?

FILE_LIST := $(LOCAL_PATH)/../../../Classes/*.cpp
LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

I wouldn’t use wildcards for the folders, because this way you can’t mix platform specific code within the classes folder.

Yes, I agree with you. I have tried to find a solution to auto generate android.mk from xcode project, but it is problem that how to avoid platform specific code.

Try this

But this is using wildcard and as was noted before, it’s bad idea?
I’m actually don’t know what that is… so finally I’ve just specified manually each .cpp file. Probably this is best solution? So I can include platform specific classes later, as I understand.

You can separate iOS and android code with different extension, for example .mm for iOS code, and .cpp for android.

And .mm file will be ignored by this wildcard. This is just one approach.

But this will ignore too? So what’s the difference?

the walk function will traverse down the sub directory. That’s the only difference.

I would recomend to place platfrom specific files to subdfolder in Classes in this case:

LOCAL_SRC_FILES := hellocpp/main.cpp \
 $(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/Android/*.cpp))


LOCAL_C_INCLUDES := $(CLASSES_PATH) \ $(CLASSES_PATH)/Android
2 Likes

Thanks for your simple and cool suggestion :sunny: