Cocos2d-x tutorial (38)-iOS porting Android, cocos2d-x-ios
Welcome to Cocos2d-x chat group: 193411763
Reprinted please indicate the original source: http://blog.csdn.net/u012945598/article/details/44338659
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------
My development environment:
Mac OS X 10.9.5
Cocos2d-x 3.3 final Version
Xcode 6.1.1
This article mainly records some problems I encountered during transplantation.
(1) modify the Android. mk File
The project is based on Lua. As mentioned in previous articles, the file structure of Lua project is different from that of C ++, the procedures for porting C ++ projects are relatively simpler. Whether it is a C ++ project or a Lua project, modify Android. mk files are all required. The directory of this file is located in the Lua project: Project project file/frameworks/runtime-src/proj. android/jni/Android. mk. Open the project file to view the proj. android folder.
You can compare it to Android in an empty C ++ HelloWorld project and an empty Lua project. the difference between mk files. Here I only give the final Android of my project. mk file for your reference (based on the Lua project, C ++ may need some modifications ).
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := cocos2dlua_sharedLOCAL_MODULE_FILENAME := libcocos2dluadefine walk $(wildcard $(1)) $(foreach e,$(wildcard $(1)/*),$(call walk,$(e)))endefALLFILES = $(call walk,$(LOCAL_PATH)/../../Classes)FILE_LIST := hellolua/main.cppFILE_LIST += $(filter %.cpp,$(ALLFILES))FILE_LIST += $(filter %.c,$(ALLFILES))FILE_INCLUDES := $(shell find $(LOCAL_PATH)/../../Classes -type d)LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_C_INCLUDES += $(shell ls -FR $(LOCAL_C_INCLUDES) | grep $(LOCAL_PATH)/$ )LOCAL_C_INCLUDES := $(LOCAL_C_INCLUDES:$(LOCAL_PATH)/%:=$(LOCAL_PATH)/%)LOCAL_STATIC_LIBRARIES := cocos2d_lua_staticLOCAL_STATIC_LIBRARIES += cocostudio_staticLOCAL_STATIC_LIBRARIES += cocos2dx_staticinclude $(BUILD_SHARED_LIBRARY)$(call import-module,scripting/lua-bindings/proj.android)
The above is the complete Android. mk file in my current project.
(2) the header file cannot be found during compilation.
If. the mk file has been modified. During the cross-compilation process, we may encounter a problem where the file cannot be found. The file here refers to some files in Cocos, for example, I used the GUI in the project and introduced the CocosGUI. h header file, but cannot be found during compilation. To solve this problem, complete the path of the header file, such as CocosGUI. h is located in the ui folder in version 3.3, so # include "ui/CocosGUI must be written during reference. h ". In iOS projects, errors are not reported if you do not write the ui, but problems may occur during compilation.
(3) custom Lua binding.
In our Lua project, we usually encounter the Interaction Problem between C ++ and Lua. At this time, we will map some methods of C ++ to Lua, that is, using lua_binding. If you have not bound the custom C ++ method to Lua, you can ignore this issue. If it is bound, you need to modify another. mk file to complete compilation.
Open the project file name/frameworks/cocos2d-x/cocos/scripting/lua-bindings/proj. android/Android. mk
All the C ++ files to be compiled in the lua_bindings project file are completed in this mk file, what we need to do is add the custom ing file to the appropriate location, such:
(4) header file reference for ing files
In our custom ing file, you must reference the cpp file in the Classes folder of the project. If we only write # include "xxx. h "there is no problem in iOS, but during compilation, the system will also prompt that the xxx file cannot be found. The full path of the file must be added here. For example, you need to introduce xxx. h file, find this file, right-click to display the introduction, and the displayed path is the path we want to write here. The best method here is to write a method to obtain the full path of the file, otherwise there will be problems in version management if the write is dead locally.
(5) resource file name
Although Chinese names can be used for resources in iOS, normal people know that Chinese names are not recommended. Although there is no problem in iOS, an error will also be reported when naming resources in Chinese during cross-compilation.
(6). c file
In my first question, one row is written: FILE_LIST + =$ (filter %. c, $ (ALLFILES ))
This is because the author uses the cjson library in the project, and the cjson uses the C source file. Therefore, it is not enough to compile C ++ only during compilation. c file compilation, otherwise it cannot be used.