标签:
1 def build(ndk_build_param,android_platform,build_mode): 2 3 ////获取ndk_root -- NDK_ROOT = os.environ[‘NDK_ROOT‘] 4 ndk_root = check_environment_variables() //获取ndk_root 5 sdk_root = None 6 select_toolchain_version() //选择编译工具版本 7 8 //获取当前目录 9 current_dir = os.path.dirname(os.path.realpath(__file__)) 10 11 //获取cocos_root库根目录,这个因为我们创建工程时拷贝了 12 //库源码,所以cocos_root目录使用的是当前目录相对目录 13 //如果我们的工程和库相对位置不是这样的,那我们只需要 14 //把此处修改一些就可以了。 15 //例如cocos_root = os.path.join("E:\otherpro\cocos2d-x-3.0\project\starGame\wipeStar\cocos2d") 16 cocos_root = os.path.join(current_dir, "../cocos2d") 17 18 //android 工程的根目录 19 app_android_root = current_dir 20 21 //拷贝资源文件,即把Resources -->> assets 22 copy_resources(app_android_root) 23 24 if android_platform is not None: 25 //获取SDK路径 -- SDK_ROOT = os.environ[‘ANDROID_SDK_ROOT‘] 26 sdk_root = check_environment_variables_sdk() 27 if android_platform.isdigit(): 28 android_platform = ‘android-‘+android_platform 29 else: 30 print ‘please use vaild android platform‘ 31 exit(1) 32 33 if build_mode is None: 34 build_mode = ‘debug‘ 35 elif build_mode != ‘release‘: 36 build_mode = ‘debug‘ 37 38 do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode) 39 40 -->>do_build分析: 41 42 def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode): 43 44 //得到NDK下ndk-build的路径 45 ndk_path = os.path.join(ndk_root, "ndk-build") 46 47 # windows should use ";" to seperate module paths 48 platform = sys.platform 49 //生成ndk_module_path参数,也就是执行ndk-build是需要NDK_MODULE_PATH路径, 50 //这里我们也可以根据自己的需求修改 51 52 if platform == ‘win32‘: 53 ndk_module_path = ‘NDK_MODULE_PATH=%s;%s/external;%s/cocos‘ % (cocos_root, cocos_root, cocos_root) 54 else: 55 ndk_module_path = ‘NDK_MODULE_PATH=%s:%s/external:%s/cocos‘ % (cocos_root, cocos_root, cocos_root) 56 57 num_of_cpu = get_num_of_cpu() 58 59 //根据传进来的参数,生成编译命令,ndk_build_param(我们执行脚本时-n指定的参数) 60 //其实这个参数都是传给ndk-build命令的。 61 if ndk_build_param == None: 62 command = ‘%s -j%d -C %s %s‘ % (ndk_path, num_of_cpu, app_android_root, ndk_module_path) 63 else: 64 command = ‘%s -j%d -C %s %s %s‘ % (ndk_path, num_of_cpu, app_android_root, ‘‘.join(str(e) for e in ndk_build_param), ndk_module_path) 65 if os.system(command) != 0: 66 raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") 67 elif android_platform is not None: 68 sdk_tool_path = os.path.join(sdk_root, "tools/android") 69 cocoslib_path = os.path.join(cocos_root, "cocos/2d/platform/android/java") 70 command = ‘%s update lib-project -t %s -p %s‘ % (sdk_tool_path,android_platform,cocoslib_path) 71 if os.system(command) != 0: 72 raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") 73 command = ‘%s update project -t %s -p %s -s‘ % (sdk_tool_path,android_platform,app_android_root) 74 if os.system(command) != 0: 75 raise Exception("update project [ " + app_android_root + " ] fails!") 76 buildfile_path = os.path.join(app_android_root, "build.xml") 77 command = ‘ant clean %s -f %s -Dsdk.dir=%s‘ % (build_mode,buildfile_path,sdk_root) 78 79 //执行命令 80 os.system(command)
来自:http://blog.csdn.net/tianxiawuzhei/article/details/44984217
标签:
原文地址:http://www.cnblogs.com/code4app/p/4692763.html