内容目录
说白了就是自动给构建安卓项目的时候加上class名字 像这样
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) $(call import-add-path,$(LOCAL_PATH)/../../cocos2d) $(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external) $(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/BaseAI.cpp \ ../../Classes/BaseFSM.cpp \ ../../Classes/BaseRole.cpp \ ../../Classes/ControlLayer.cpp \ ../../Classes/DataManager.cpp \ ../../Classes/DialogLayer.cpp \ ../../Classes/FlyText.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/HRocker.cpp \ ../../Classes/MapLayer.cpp \ ../../Classes/MenuLayer.cpp \ ../../Classes/OperateLayer.cpp \ ../../Classes/propertyManager.cpp \ ../../Classes/RoleCardController.cpp \ ../../Classes/SceneManager.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes # _COCOS_HEADER_ANDROID_BEGIN # _COCOS_HEADER_ANDROID_END LOCAL_STATIC_LIBRARIES := cocos2dx_static # _COCOS_LIB_ANDROID_BEGIN # _COCOS_LIB_ANDROID_END include $(BUILD_SHARED_LIBRARY) $(call import-module,.) # _COCOS_LIB_IMPORT_ANDROID_BEGIN # _COCOS_LIB_IMPORT_ANDROID_END
代码写在这个文件里 下面是写入class的代码 build_native.py
def getFileNames(path): fileList = [] files = os.listdir(path) for f in files: if(os.path.isfile(path + '/' + f)): if(f[0] == '.' or f.find(".cpp")==-1): continue fileList.append(f) return fileList def inAndroidmkClass(): current_dir = os.path.dirname(os.path.realpath(__file__)) print current_dir[:current_dir.rfind("/")] anfile_dir = os.path.join(current_dir, "jni/Android.mk") print "anfile_dir:"+anfile_dir class_dir =os.path.join(current_dir[:current_dir.rfind("/")],"Classes") print "class_dir:"+class_dir f=open(anfile_dir); txt=f.read(); f.close(); pos=txt.find("LOCAL_SRC_FILES"); pre=txt[0:pos]; pos2=txt.find("LOCAL_C_INCLUDES"); last=txt[pos2:]; intxt="LOCAL_SRC_FILES := hellocpp/main.cpp \\\n"; files= getFileNames(class_dir); for f in files: intxt+=" ../../Classes/"+f+" \\\n"; intxt+="\n"; f=open(anfile_dir,"w"); f.write(pre+intxt+last); f.close(); print "write to android.mk completed" # print pre+intxt+last;
记得在main中引用
inAndroidmkClass()