Is there are way to create android.mk automatically

the file is look like :

LOCAL_SRC_FILES := main.cpp …/…/…/Classes/AppDelegate.cpp …/…/…/Classes/GameMenu/GameMainMenu.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/…/…/cocos2dx $(LOCAL_PATH)/…/…/…/…/cocos2dx/platform $(LOCAL_PATH)/…/…/…/…/cocos2dx/include $(LOCAL_PATH)/…/…/…/…/CocosDenshion/include $(LOCAL_PATH)/…/…/…/Classes $(LOCAL_PATH)/…/…/…/Classes/GameMenu

so any class i add ,i must modify the android.mk file,is any tool can fix that??

No now, may be you can write a script to do it and share with the community.

1 Like

OK,i will ,but not today,and i am not so good at shell,may be i will use .exe(windows) or .app(mac os),sorry linux guys :slight_smile:

Include all **.cpp files automatically in Android.mk:
** For Android.mk in “/Classes” folder (or you must correct the script)
* If I want to rebuild project I resave Android.mk (this maybe dummy way) or you need to use the “always_rebuild” key (I don’t know it)

define all-cpp-files-under
$(patsubst ./%,%, \
  $(shell cd $(LOCAL_PATH) ; \
          find $(1) -name "*.cpp" -and -not -name ".*") \
 )
endef

define all-subdir-cpp-files
$(call all-cpp-files-under,.)
endef

LOCAL_SRC_FILES += $(call all-subdir-cpp-files)

Maybe I should share this in other place?

it’s good…

O!
I found “…/HelloWorld/android/jni/list.sh” with function list_alldir().
It look like useful for this issue, but don’t used by default… strange.

OK~ I fix android.mk to create android.mk automatically~
It can find any subdirs and **.cpp that u add in “Classes”
<pre>
LOCAL_PATH := $
include $
LOCAL_MODULE := game_logic

dirs := $ ~~type d)
cppfilestemp1 := $~~type d)
cppfilestemp2 := $ -name**.cpp)
cppfilestemp3 := $(sort $(cppfilestemp2))
cppfiles := $(subst $(LOCAL_PATH)/,$(cppfilestemp3))

LOCAL_SRC_FILES := $(cppfiles)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/cocos2dx $(LOCAL_PATH)/…/…/cocos2dx/platform $(LOCAL_PATH)/…/…/cocos2dx/include $(LOCAL_PATH)/…/…/CocosDenshion/include $(LOCAL_PATH)/…/…/cocos2dx/lua_support $(dirs)

It’s for cocos2d-1.0.1-x-0.10.0 !

or u can download file and cover it

Hi!

Is it okay for .mm classes? cause i have .mm classes on my iphone cocos2d-x project,
and after i modified Android.mk file. I got this error.

Compile++ thumb : game <= ClassicGameplay.mm
fatal error: directory compilation terminated.
make: * [obj/local/armeabi/objs-debug/game/////source/states/ClassicGameplay.o] Error 1
ERROR: NDK build failed.

My Android.mk looks like this:

LOCAL_PATH := $(call my-dir)
>
include $(CLEAR_VARS)
>
LOCAL_MODULE := game_shared
>
LOCAL_MODULE_FILENAME := libgame
>
FILE_LIST := $(wildcard $(LOCAL_PATH)/…/…/Classes/Actions/*.cpp)
FILE_LIST = $/…/…/Classes/Constants/.cpp)
FILE_LIST *= $/…/…/Classes/Helpers/
.cpp)
FILE_LIST = $/…/…/Classes/GameObjects/.cpp)
FILE_LIST = $/…/…/Classes/Scenes/*.cpp)
FILE_LIST
= $/…/…/Classes/Singletons/
.cpp)
FILE_LIST
= $/…/…/Classes/JNICalls/**.cpp)
FILE_LIST
= $/…/…/Classes/**.cpp)
>
LOCAL_SRC_FILES := helloworld/main.cpp
>
LOCAL_SRC_FILES*= $(FILE_LIST:$(LOCAL_PATH)/=)
>
>
LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/Classes
>
>
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static
>
include $(BUILD_SHARED_LIBRARY)
>
$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)

Compile all cpp in each folder. It is helpful if you add new cpps and don’t want to add manually (but folders must be). All headers are relatives.

1 Like

hm…

  1. Android don’t understands Obj C language
  2. "name *.cpp" it takes cpp files only

Hi! so… I badly need to convert obj-c codes to c++ D:
Thanks BTW! :smiley:

hello,
I attach an image with the error …… If I made any mistake then post for the response

Akas Middha wrote:

hello,
I attach an image with the error …… If I made any mistake then post for the response

You are having a permission error. Make sure you run the BAT file with Admin access.

has anyone here have used the list.sh file under the jni folder of pre-created android project of cocos2d-x? :slight_smile:

I’ve made a self-updated Android.mk with Cog utility. It requires python to be installed. If there is interest in such approach I can share it with you guys.

Would you mind if I try your utility? :smiley:

Sure, I’ve put the code to github: https://github.com/bialix/cog-for-android.mk
It’s based on HelloWorld sample from cocos2dx sources (I have v.2.0.1 here but I think it should work for newer versions too).

You need Python 2.6 or higher to be available for your build environment. If you have to use older versions of Python you may need to downgrade Cog utility itself, see it’s homepage for details.

My script tries to update Android.mk on every invocation of build_native.sh. That’s pretty quick compared to overall slowness of Eclipse ;)
You can disable automatic update of Android.mk in build_native.sh and simply run update-androidmk.sh script from jni subdir manually if you like.
Also my script tries to collect all subfloders in Classes where C++ files are located and update LOCAL_C_INCLUDES so you don’t have to worry about #include from different folders . If you need to disable this
you need simply delete couple of lines in Android.mk - I’ve left a comment in the appropriate place.

Using power of Python it’s easy to create more sophisticated files list collector/makefile generator, e.g. exclude some files from Android build etc.

I’ve tried FoXx WeLl approach, and before that I’ve tried writing my own script to generate the Android.mk, but anytime I introduced an automatically generated file to my project it threw an error, saying that main.cpp cannot find “#include”AppDelegate.h“”. Before introducing the file, everything worked thine, the project built & run.

I’m using cocos2d-2.1rc0-x-2.1.2 @ March 20.2013

Edit —————

I’ve made a typo in my script, and got it working! If anyone is interested you can see it here : http://www.cocos2d-x.org/boards/6/topics/28444

See the following post (Simplified Chinese)

System will select all cpp files in folders.
But it is needed to make sure the source files in folders are all valid.

1 Like

I can vouch for Pawel’s script :slight_smile: