Lua script implements automatic generation of APK packages _lua

Source: Internet
Author: User
Tags lua svn svn update

can be expanded to suit your needs.

Use the previous tool path and the first two of the target path, or you need to set it yourself.

Some small functions jit_file copy_file I will not post it is simpler to Luajit and copy.

Copy Code code as follows:

--Authors:sails Kite @oschina
--date:20th, August, 2014
--Note:
--This is used for COCOS2DX + Lua
--a script to making. APK file for Android platform
---Make sure your have installed Java, ant, Android SDK, NDK, SVN, JIT
--Also plz check and rewrite following paths before you with this script
--Remarks:
--The script would update your Cocos engine directory and your Lua script which probably is
--then it should jit your Lua files, use Asmaker to encrypt your files
--All files and would move to this folder Proj.android/assets
--finally it'll 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.execute (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-build ' ... '-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 = ' pushd '. Work_dir ... ' &call '.. Ant_home ... ' \\bin\\ant Release '
Local ant_re = Run_one_cmd (ant_cmd)
If Ant_re:find ("failed") then
Print ("Build apk failed!", Ant_re)
Os.exit (1)
End

The above code is the entire content that this article wants to share, hope everybody can like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.