Android-cocos2dx

Android-cocos2dx
0.0 0

#1

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.


#2

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

#3

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


#4

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


#5

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

#6

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.


#7

Try this


#8

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.


#9

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.


#10

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


#11

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


#12

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

#13

Thanks for your simple and cool suggestion :sunny: