-- Authors: sails logs @ oschina -- Date: 20th, August, 2014 -- Note: -- This is used for Cocos2dx + Lua -- This is a script to making. APK file for android platform -- Make sure you have installed java, ant, android sdk, ndk, svn, jit -- Also plz check and rewrite following paths before you use this script -- Remarks: -- The script will update your cocos engine directory and your Lua script which probably is Resources -- Then it shoshould jit your Lua files, use ASMaker to encrypt your Lua-jit files -- All files and resources will move to this folder proj. android/assets -- Finally it will make a. APK package with ANT Require ('support ') -- Tools paths Local JAVA_HOME = 'C: \ Program Files \ Java \ jdk1.8.0 _ 05' Local ANT_HOME = 'd: \ ProgramSoftware \ apache-ant-1.9.4' Local ANDROID_HOME = '"D: \ ProgramSoftware \ android sdk \ sdk "' Local NDK_HOME = 'd: \ ProgramSoftware \ android-ndk-r9d-windows-x86_64 \ android-ndk-r9d' Local SVN_HOME = 'C: \ Program Files \ TortoiseSVN \ bin \\' -- Target paths Local ENGINE_DIR = 'd: \ engine' Local WORK_DIR = 'd: \ engine \ projects \ XXXX \ proj. android' Local RESOURCES_DIR = WORK_DIR .. '\ .. \ Resources' Local ASSETS_DIR = WORK_DIR .. '\ assets' -- Function detect directory Local function dir_exist (dir) Return OS .exe cute (string. format ('pushd "% s"> nul 2> nul & popd ', dir )) End -- Remove old assets If dir_exist (ASSETS_DIR) then Rmdir (ASSETS_DIR) End -- Remove old APK Local old_apk, err = io. open (WORK_DIR .. '\ bin \ XXXX-release.apk ') If err = nil then Old_apk: close () Delfile (WORK_DIR .. '\ bin \ XXXX-release.apk ') End -- Svn update -- Check -- Svn_up (ENGINE_DIR) -- Svn_up (WORK_DIR ..'\\..') -- Luajit -- Iter directory Local cmd = string. format ("pushd % q & dir/B/s & popd", RESOURCES_DIR) Local file_list = io. popen (cmd) For line in file_list: lines () do Line_to = string. gsub (line, 'resources', 'resources _ jit ') If dir_exist (line) then Check_mk_path (line_to) Else If (string. find (line, '. lua $') then Jit_file (WORK_DIR, line, line_to) Else Copy_file (line, line_to) End End End File_list: close () -- Encryption with ASmaker Local enc_cmd = WORK_DIR .. '\ ASmaker.exe '.. '-I '.. WORK_DIR .. '\\.. \ Resources_jit '.. "-o ".. ASSETS_DIR .. '-f. lua-e. exe' Local enc_re = run_one_cmd (enc_cmd) If enc_re: find ("failed") then Print ("ASmaker encrypted folder failed! ", Enc_re) OS. exit (1) End -- Ndk build Local ndk_cmd = 'call '.. NDK_HOME .. '\ ndk-built '.. '-C '.. WORK_DIR .. ''.. 'ndk _ MODULE_PATH = '.. ENGINE_DIR .. ';'.. ENGINE_DIR .. '\ cocos2dx \ platform \ third_party \ android \ prebuilt' Local ndk_re = run_one_cmd (ndk_cmd) If ndk_re: find ("error") then Print ("NDK build failed! ", Ndk_re) OS. exit (1) End -- Android update Local and_cmd = 'call' .. ANDROID_HOME... '\ tools \ android'... 'Update project-p' .. WORK_DIR Local and_re = run_one_cmd (and_cmd) And_cmd = 'call "'.. ANDROID_HOME .. '\ tools \ android "'.. 'Update lib-project-p '.. ENGINE_DIR .. '\ cocos2dx \ platform \ android \ Java' And_re = run_one_cmd (and_cmd) -- Ant Local ant_cmd = 'push' .. WORK_DIR... '& call'... ANT_HOME...' \ bin \ ant release' Local ant_re = run_one_cmd (ant_cmd) If ant_re: find ("failed") then Print ("failed to generate APK! ", Ant_re) OS. exit (1) End |