@@ -411,6 +411,58 @@ def gradle_build_apk(self, build_mode):
411
411
cmd = '"%s" --parallel --info assemble%s' % (gradle_path , mode_str )
412
412
self ._run_cmd (cmd , cwd = self .app_android_root )
413
413
414
+ class LuaBuildType :
415
+ UNKNOWN = - 1
416
+ ONLY_BUILD_64BIT = 1
417
+ ONLY_BUILD_32BIT = 2
418
+ BUILD_32BIT_AND_64BIT = 3
419
+
420
+ def _do_get_build_type (self , str ):
421
+ # remove the '#' and the contents after it
422
+ str = str .split ('#' )[0 ]
423
+ build_64bit = str .find ('arm64-v8a' ) != - 1
424
+
425
+ # check if need to build other architecture
426
+ build_other_arch = False
427
+ other_archs = ('armeabi' , 'armeabi-v7a' , 'x86' ) # other arches are not supported
428
+ for arch in other_archs :
429
+ if str .find (arch ) != - 1 :
430
+ build_other_arch = True
431
+ break
432
+
433
+ if build_64bit or build_other_arch :
434
+ if build_64bit :
435
+ if build_other_arch :
436
+ print 'build 64bit and 32bit'
437
+ return LuaBuildType .BUILD_32BIT_AND_64BIT
438
+ else :
439
+ print 'only build 64bit'
440
+ return LuaBuildType .ONLY_BUILD_64BIT
441
+ else :
442
+ print 'only build 32bit'
443
+ return LuaBuildType .ONLY_BUILD_32BIT
444
+
445
+ return LuaBuildType .UNKNOWN
446
+
447
+ # check if arm64-v8a is set in Application.mk
448
+ def _get_build_type (self , param_of_appabi ):
449
+
450
+ # get build type from parameter
451
+ if param_of_appabi :
452
+ return self ._do_get_build_type (param_of_appabi )
453
+
454
+ # get build type from Application.mk
455
+ applicationmk_path = os .path .join (self .app_android_root , "jni/Application.mk" )
456
+ with open (applicationmk_path ) as f :
457
+ for line in f :
458
+ if line .find ('APP_ABI' ) == - 1 :
459
+ continue
460
+ build_type = self ._do_get_build_type (line )
461
+ if build_type != LuaBuildType .UNKNOWN :
462
+ return build_type
463
+
464
+ return LuaBuildType .UNKNOWN
465
+
414
466
def do_build_apk (self , build_mode , no_apk , output_dir , custom_step_args , compile_obj ):
415
467
if self .use_studio :
416
468
assets_dir = os .path .join (self .app_android_root , "app" , "assets" )
@@ -441,11 +493,37 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, compile
441
493
442
494
# copy resources
443
495
self ._copy_resources (custom_step_args , assets_dir )
444
-
445
496
446
497
# check the project config & compile the script files
447
498
if self ._project ._is_lua_project ():
448
- compile_obj .compile_lua_scripts (assets_dir , assets_dir )
499
+ print "generate byte code ............"
500
+ src_dir = os .path .join (assets_dir , 'src' )
501
+ build_type = self ._get_build_type (compile_obj .app_abi )
502
+
503
+ # only build 64bit
504
+ if build_type == LuaBuildType .ONLY_BUILD_64BIT :
505
+ dst_dir = os .path .join (assets_dir , 'src/64bit' )
506
+ compile_obj .compile_lua_scripts (src_dir , dst_dir , True )
507
+ # remove unneeded lua files
508
+ compile_obj ._remove_file_with_ext (src_dir , '.lua' )
509
+ shutil .rmtree (os .path .join (src_dir , 'cocos' ))
510
+
511
+ # only build 32bit
512
+ if build_type == LuaBuildType .ONLY_BUILD_32BIT :
513
+ # build 32-bit bytecode
514
+ compile_obj .compile_lua_scripts (src_dir , src_dir , False )
515
+
516
+ # build 32bit and 64bit
517
+ if build_type == LuaBuildType .BUILD_32BIT_AND_64BIT :
518
+ # build 64-bit bytecode
519
+ dst_dir = os .path .join (assets_dir , 'src/64bit' )
520
+ compile_obj .compile_lua_scripts (src_dir , dst_dir , True )
521
+ # build 32-bit bytecode
522
+ compile_obj .compile_lua_scripts (src_dir , src_dir , False )
523
+
524
+ if build_type == LuaBuildType .UNKNOWN :
525
+ # haven't set APP_ABI in parameter and Application.mk, default build 32bit
526
+ compile_obj .compile_lua_scripts (src_dir , src_dir , False )
449
527
450
528
if self ._project ._is_js_project ():
451
529
compile_obj .compile_js_scripts (assets_dir , assets_dir )
0 commit comments