安卓打包问题 暴强推荐 patyhon 命令 导出.so文件

来源:互联网 发布:java array 截取字数组 编辑:程序博客网 时间:2024/06/05 05:41

我不会什么cocos打包命令,我自己写了个生成.so文件命令       我主程的原话     妈的 真的是强

可以解决项目繁多打包久治不愈问题



使用说明

***********************************更新***********************************
使用现proj.android中的mk文件(已修改)


使用ndk.build.py进行.so文件的生成




新机器的话 需要在   final cmd  后的一段代码中   NDK_Root 前加  clean   执行清除缓存命令 






然后再使用此命令生成.so文件


然后  cocos compile  -p android打debug包    或是 使用eclipse进行打包 




***********************************清除命令(注意路径)*************************
D:\pack\android-ndk-r10e\ndk-build -C C:\Users\zhanghow\Desktop\client\proj.android clean NDK_MODULE_PATH=C:\Users\zhanghow\Desktop\client\proj.android\../cocos2d/;C:\Users\zhanghow\Desktop\client\proj.android\../cocos2d/cocos;C:\Users\zhanghow\Desktop\client\proj.android\../cocos2d/external -j16 NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1





#                           文件


 #!/usr/bin/python
# build_native.py
# Build native codes

# Please use cocos console instead




import sys
import os, os.path
import shutil
import subprocess
from optparse import OptionParser


def remove_c_libs(libs_dir):
    for file_name in os.listdir(libs_dir):
        lib_file = os.path.join(libs_dir,  file_name)
        if os.path.isfile(lib_file):
            ext = os.path.splitext(lib_file)[1]
            if ext == ".a" or ext == ".so":
                os.remove(lib_file)




def build(build_mode, ndk_build_param):


    print build_mode, ndk_build_param


    current_dir = os.path.dirname(os.path.realpath(__file__))
    cocos_root = os.path.join(current_dir, "../cocos2d/")


    app_android_root = current_dir
    ndk_path = os.environ.get('NDK_ROOT');
    if ndk_path == "":
        ndk_path = os.environ.get('ANDROID_NDK_ROOT');
    ndk_path = os.path.join(ndk_path, "ndk-build")
    ndk_path = ndk_path.replace("\ ", " ").replace(" ", "\ ")

    if build_mode is None:
        build_mode = 'debug'
    elif build_mode != 'release':
        build_mode = 'debug'
    


    print "Run Ndk Build At ", app_android_root, build_mode
        
    ndk_module_path = cocos_root + ";" + cocos_root + "cocos" + ";" + cocos_root + "external"

# + ";" + cocos_root + "cocos/scripting"

    ndk_module_path = 'NDK_MODULE_PATH=' + ndk_module_path + " -j16"


    # print ndk_module_path
    if ndk_build_param is None:
        ndk_build_cmd = '%s -C %s %s' % (ndk_path, app_android_root ,ndk_module_path)
    else:
        ndk_build_cmd = '%s -C %s %s %s' % (ndk_path, app_android_root, ' '.join(ndk_build_param), ndk_module_path)


    ndk_build_cmd = '%s NDK_TOOLCHAIN_VERSION=%s' % (ndk_build_cmd, 4.9)
    if build_mode == 'debug':
        ndk_build_cmd = '%s NDK_DEBUG=1' % ndk_build_cmd


    obj_local_dir = os.path.join(app_android_root, "obj", "local")
    if os.path.isdir(obj_local_dir):
        for abi_dir in os.listdir(obj_local_dir):
            static_file_path = os.path.join(app_android_root, "obj", "local", abi_dir)
            if os.path.isdir(static_file_path):
                print "Remove Existing Lib Files From ", static_file_path
                remove_c_libs(static_file_path)


    so_file_path = os.path.join(app_android_root, "libs", "armeabi", "libgame.so");
    if os.path.isfile(so_file_path):
        os.remove(so_file_path)
    print "Remove Exiting File", so_file_path
    # os.remove()


    print "Final Cmd\n", ndk_build_cmd
    ret = subprocess.call(ndk_build_cmd, shell=True, cwd=None);
    if ret != 0:
        sys.exit(1)
    else:
        sys.exit(0)
    # print "test123"
    # command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) 
    # if os.system(command) != 0:
    #     raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")


# -------------- main --------------
if __name__ == '__main__':


    parser = OptionParser()
    parser.add_option("-n", "--ndk", dest="ndk_build_param", help='it is not used', action="append")
    parser.add_option("-p", "--platform", dest="android_platform", 
    help='it is not used')
    parser.add_option("-b", "--build", dest="build_mode", 
    help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
    (opts, args) = parser.parse_args()
    
    # print "Please use cocos console instead.\n"
    
    build(opts.build_mode, opts.ndk_build_param)








0 0
原创粉丝点击