Lua script automatically generates the APK package

Source: Internet
Author: User
Tags svn update

Lua script automatically generates the APK package

This article mainly introduces the Lua script to automatically generate the APK package. This script applies to cocos2dx + lua projects. For more information, see

The last time I used bat to write a script to generate an APK package, I felt that the scalability and syntax of bat were terrible. This time I used lua to rewrite a script.

You can expand it as needed.

You need to set the first two tools and target paths before using them.

Some small functions, such as jit_file copy_file, are simple and used for luajit and copy.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

-- 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

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.