@@ -27,11 +27,6 @@ class AndroidBuilder(object):
27
27
CFG_KEY_ALIAS = "alias"
28
28
CFG_KEY_ALIAS_PASS = "alias_pass"
29
29
30
- ANT_KEY_STORE = "key.store"
31
- ANT_KEY_ALIAS = "key.alias"
32
- ANT_KEY_STORE_PASS = "key.store.password"
33
- ANT_KEY_ALIAS_PASS = "key.alias.password"
34
-
35
30
GRADLE_KEY_STORE = "RELEASE_STORE_FILE"
36
31
GRADLE_KEY_ALIAS = "RELEASE_KEY_ALIAS"
37
32
GRADLE_KEY_STORE_PASS = "RELEASE_STORE_PASSWORD"
@@ -45,25 +40,20 @@ class AndroidBuilder(object):
45
40
GRADLE_PROP_LUA_ENCRYPT_KEY = 'PROP_LUA_ENCRYPT_KEY'
46
41
GRADLE_PROP_LUA_ENCRYPT_SIGN = 'PROP_LUA_ENCRYPT_SIGN'
47
42
48
- def __init__ (self , verbose , app_android_root , no_res , proj_obj , ndk_mode , app_abi , use_studio = False , gradle_support_ndk = False ):
43
+ def __init__ (self , verbose , app_android_root , no_res , proj_obj , ndk_mode , app_abi , gradle_support_ndk = False ):
49
44
self ._verbose = verbose
50
45
51
46
self .app_android_root = app_android_root
52
47
self ._no_res = no_res
53
48
self ._project = proj_obj
54
- self .use_studio = use_studio
55
49
self .gradle_support_ndk = gradle_support_ndk
56
50
self .app_abi = app_abi
57
51
self .ndk_mode = ndk_mode
58
52
59
53
# check environment variable
60
- if self .use_studio :
61
- self .ant_root = None
62
- self .sign_prop_file = os .path .join (self .app_android_root , 'app' , "gradle.properties" )
63
- else :
64
- self .ant_root = cocos .check_environment_variable ('ANT_ROOT' )
65
- self .sign_prop_file = os .path .join (self .app_android_root , "ant.properties" )
66
54
self .sdk_root = cocos .check_environment_variable ('ANDROID_SDK_ROOT' )
55
+ self .ant_root = None
56
+ self .sign_prop_file = os .path .join (self .app_android_root , 'app' , "gradle.properties" )
67
57
68
58
self ._parse_cfg ()
69
59
@@ -72,16 +62,10 @@ def _run_cmd(self, command, cwd=None):
72
62
73
63
def _parse_cfg (self ):
74
64
# get the properties for sign release apk
75
- if self .use_studio :
76
- self .key_store_str = AndroidBuilder .GRADLE_KEY_STORE
77
- self .key_alias_str = AndroidBuilder .GRADLE_KEY_ALIAS
78
- self .key_store_pass_str = AndroidBuilder .GRADLE_KEY_STORE_PASS
79
- self .key_alias_pass_str = AndroidBuilder .GRADLE_KEY_ALIAS_PASS
80
- else :
81
- self .key_store_str = AndroidBuilder .ANT_KEY_STORE
82
- self .key_alias_str = AndroidBuilder .ANT_KEY_ALIAS
83
- self .key_store_pass_str = AndroidBuilder .ANT_KEY_STORE_PASS
84
- self .key_alias_pass_str = AndroidBuilder .ANT_KEY_ALIAS_PASS
65
+ self .key_store_str = AndroidBuilder .GRADLE_KEY_STORE
66
+ self .key_alias_str = AndroidBuilder .GRADLE_KEY_ALIAS
67
+ self .key_store_pass_str = AndroidBuilder .GRADLE_KEY_STORE_PASS
68
+ self .key_alias_pass_str = AndroidBuilder .GRADLE_KEY_ALIAS_PASS
85
69
86
70
if self .gradle_support_ndk :
87
71
return
@@ -137,10 +121,7 @@ def _parse_cfg(self):
137
121
138
122
def has_keystore_in_signprops (self ):
139
123
keystore = None
140
- if self .use_studio :
141
- pattern = re .compile (r"^RELEASE_STORE_FILE=(.+)" )
142
- else :
143
- pattern = re .compile (r"^key\.store=(.+)" )
124
+ pattern = re .compile (r"^RELEASE_STORE_FILE=(.+)" )
144
125
145
126
try :
146
127
file_obj = open (self .sign_prop_file )
@@ -242,49 +223,23 @@ def update_project(self, android_platform):
242
223
self ._write_local_properties (self .app_android_root )
243
224
return
244
225
245
- # Android SDK removed android command & ant support from SDK tools 25.3.0
246
- # So, we should check the Android SDK tools version
247
- sdk_tools_folder = os .path .join (self .sdk_root , 'tools' )
248
- main_ver , minor_ver = self ._get_android_sdk_tools_ver (sdk_tools_folder )
249
- no_ant = False
250
- if main_ver > 25 or (main_ver == 25 and minor_ver >= 3 ):
251
- no_ant = True
252
-
253
- if not self .use_studio and no_ant :
254
- # Tip the message that ant is not supported from Android SDK tools 25.3.0
255
- raise cocos .CCPluginError (MultiLanguage .get_string ('COMPILE_ERROR_ANT_NOT_SUPPORTED' ),
256
- cocos .CCPluginError .ERROR_OTHERS )
257
-
258
- if self .use_studio :
259
- manifest_path = os .path .join (self .app_android_root , 'app' )
260
- else :
261
- manifest_path = self .app_android_root
226
+ manifest_path = os .path .join (self .app_android_root , 'app' )
262
227
263
228
# check the android platform
264
229
target_str = self .check_android_platform (self .sdk_root , android_platform , manifest_path )
265
230
266
- if no_ant :
267
- # should manually update the project
268
- self ._write_local_properties (manifest_path )
269
- self ._update_project_properties (manifest_path , target_str )
270
- else :
271
- # update project
272
- sdk_tool_path = os .path .join (sdk_tools_folder , "android" )
273
- command = "%s update project -t %s -p %s" % (cocos .CMDRunner .convert_path_to_cmd (sdk_tool_path ), target_str , manifest_path )
274
- self ._run_cmd (command )
275
-
276
- # update lib-projects
277
- self .update_lib_projects (self .sdk_root , sdk_tool_path , android_platform , manifest_path )
278
-
279
- if self .use_studio :
280
- # copy the local.properties to the app_android_root
281
- file_name = 'local.properties'
282
- src_path = os .path .normpath (os .path .join (manifest_path , file_name ))
283
- dst_path = os .path .normpath (os .path .join (self .app_android_root , file_name ))
284
- if src_path != dst_path :
285
- if os .path .isfile (dst_path ):
286
- os .remove (dst_path )
287
- shutil .copy (src_path , dst_path )
231
+ # should manually update the project
232
+ self ._write_local_properties (manifest_path )
233
+ self ._update_project_properties (manifest_path , target_str )
234
+
235
+ # copy the local.properties to the app_android_root
236
+ file_name = 'local.properties'
237
+ src_path = os .path .normpath (os .path .join (manifest_path , file_name ))
238
+ dst_path = os .path .normpath (os .path .join (self .app_android_root , file_name ))
239
+ if src_path != dst_path :
240
+ if os .path .isfile (dst_path ):
241
+ os .remove (dst_path )
242
+ shutil .copy (src_path , dst_path )
288
243
289
244
def get_toolchain_version (self , ndk_root , compile_obj ):
290
245
# it should be possible to override the toolchain
@@ -299,10 +254,7 @@ def do_ndk_build(self, ndk_build_param, build_mode, compile_obj):
299
254
300
255
toolchain_version = self .get_toolchain_version (ndk_root , compile_obj )
301
256
302
- if self .use_studio :
303
- ndk_work_dir = os .path .join (self .app_android_root , 'app' )
304
- else :
305
- ndk_work_dir = self .app_android_root
257
+ ndk_work_dir = os .path .join (self .app_android_root , 'app' )
306
258
reload (sys )
307
259
sys .setdefaultencoding ('utf8' )
308
260
ndk_path = cocos .CMDRunner .convert_path_to_cmd (os .path .join (ndk_root , "ndk-build" ))
@@ -402,30 +354,6 @@ def check_android_platform(self, sdk_root, android_platform, proj_path):
402
354
403
355
return ret
404
356
405
- def ant_build_apk (self , build_mode , custom_step_args ):
406
- app_android_root = self .app_android_root
407
-
408
- # run ant build
409
- ant_path = os .path .join (self .ant_root , 'ant' )
410
- buildfile_path = os .path .join (app_android_root , "build.xml" )
411
-
412
- # generate paramters for custom step
413
- args_ant_copy = custom_step_args .copy ()
414
- target_platform = cocos_project .Platforms .ANDROID
415
-
416
- # invoke custom step: pre-ant-build
417
- self ._project .invoke_custom_step_script (cocos_project .Project .CUSTOM_STEP_PRE_ANT_BUILD ,
418
- target_platform , args_ant_copy )
419
-
420
- command = "%s clean %s -f %s -Dsdk.dir=%s" % (cocos .CMDRunner .convert_path_to_cmd (ant_path ),
421
- build_mode , buildfile_path ,
422
- cocos .CMDRunner .convert_path_to_cmd (self .sdk_root ))
423
- self ._run_cmd (command )
424
-
425
- # invoke custom step: post-ant-build
426
- self ._project .invoke_custom_step_script (cocos_project .Project .CUSTOM_STEP_POST_ANT_BUILD ,
427
- target_platform , args_ant_copy )
428
-
429
357
def gradle_build_apk (self , build_mode , android_platform , compile_obj ):
430
358
# check the compileSdkVersion & buildToolsVersion
431
359
check_file = os .path .join (self .app_android_root , 'app' , 'build.gradle' )
@@ -547,10 +475,7 @@ def _get_build_type(self, param_of_appabi):
547
475
return self ._do_get_build_type (param_of_appabi )
548
476
549
477
# get build type from Application.mk
550
- if self .use_studio :
551
- applicationmk_path = os .path .join (self .app_android_root , "app/jni/Application.mk" )
552
- else :
553
- applicationmk_path = os .path .join (self .app_android_root , "jni/Application.mk" )
478
+ applicationmk_path = os .path .join (self .app_android_root , "app/jni/Application.mk" )
554
479
with open (applicationmk_path ) as f :
555
480
for line in f :
556
481
if line .find ('APP_ABI' ) == - 1 :
@@ -562,32 +487,27 @@ def _get_build_type(self, param_of_appabi):
562
487
return self .LuaBuildType .UNKNOWN
563
488
564
489
def do_build_apk (self , build_mode , no_apk , output_dir , custom_step_args , android_platform , compile_obj ):
565
- if self .use_studio :
566
- assets_dir = os .path .join (self .app_android_root , "app" , "assets" )
567
- project_name = None
568
- setting_file = os .path .join (self .app_android_root , 'settings.gradle' )
569
- if os .path .isfile (setting_file ):
570
- # get project name from settings.gradle
571
- f = open (setting_file )
572
- lines = f .readlines ()
573
- f .close ()
574
-
575
- pattern = r"project\(':(.*)'\)\.projectDir[ \t]*=[ \t]*new[ \t]*File\(settingsDir, 'app'\)"
576
- for line in lines :
577
- line_str = line .strip ()
578
- match = re .match (pattern , line_str )
579
- if match :
580
- project_name = match .group (1 )
581
- break
582
-
583
- if project_name is None :
584
- # use default project name
585
- project_name = 'app'
586
- gen_apk_folder = os .path .join (self .app_android_root , 'app/build/outputs/apk' , build_mode )
587
- else :
588
- assets_dir = os .path .join (self .app_android_root , "assets" )
589
- project_name = self ._xml_attr (self .app_android_root , 'build.xml' , 'project' , 'name' )
590
- gen_apk_folder = os .path .join (self .app_android_root , 'bin' )
490
+ assets_dir = os .path .join (self .app_android_root , "app" , "assets" )
491
+ project_name = None
492
+ setting_file = os .path .join (self .app_android_root , 'settings.gradle' )
493
+ if os .path .isfile (setting_file ):
494
+ # get project name from settings.gradle
495
+ f = open (setting_file )
496
+ lines = f .readlines ()
497
+ f .close ()
498
+
499
+ pattern = r"project\(':(.*)'\)\.projectDir[ \t]*=[ \t]*new[ \t]*File\(settingsDir, 'app'\)"
500
+ for line in lines :
501
+ line_str = line .strip ()
502
+ match = re .match (pattern , line_str )
503
+ if match :
504
+ project_name = match .group (1 )
505
+ break
506
+
507
+ if project_name is None :
508
+ # use default project name
509
+ project_name = 'app'
510
+ gen_apk_folder = os .path .join (self .app_android_root , 'app/build/outputs/apk' , build_mode )
591
511
592
512
# gradle supports copy assets & compile scripts from engine 3.15
593
513
if not self .gradle_support_ndk :
@@ -634,10 +554,7 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
634
554
self ._gather_sign_info ()
635
555
636
556
# build apk
637
- if self .use_studio :
638
- self .gradle_build_apk (build_mode , android_platform , compile_obj )
639
- else :
640
- self .ant_build_apk (build_mode , custom_step_args )
557
+ self .gradle_build_apk (build_mode , android_platform , compile_obj )
641
558
642
559
# copy the apk to output dir
643
560
if output_dir :
@@ -731,26 +648,22 @@ def _copy_resources(self, custom_step_args, assets_dir):
731
648
self ._project .invoke_custom_step_script (cocos_project .Project .CUSTOM_STEP_POST_COPY_ASSETS , target_platform , cur_custom_step_args )
732
649
733
650
def get_apk_info (self ):
734
- if self .use_studio :
735
- manifest_path = os .path .join (self .app_android_root , 'app' )
736
- gradle_cfg_path = os .path .join (manifest_path , 'build.gradle' )
737
- package = None
738
- if os .path .isfile (gradle_cfg_path ):
739
- # get package name from build.gradle
740
- f = open (gradle_cfg_path )
741
- for line in f .readlines ():
742
- line_str = line .strip ()
743
- pattern = r'applicationId[ \t]+"(.*)"'
744
- match = re .match (pattern , line_str )
745
- if match :
746
- package = match .group (1 )
747
- break
748
-
749
- if package is None :
750
- # get package name from AndroidManifest.xml
751
- package = self ._xml_attr (manifest_path , 'AndroidManifest.xml' , 'manifest' , 'package' )
752
- else :
753
- manifest_path = self .app_android_root
651
+ manifest_path = os .path .join (self .app_android_root , 'app' )
652
+ gradle_cfg_path = os .path .join (manifest_path , 'build.gradle' )
653
+ package = None
654
+ if os .path .isfile (gradle_cfg_path ):
655
+ # get package name from build.gradle
656
+ f = open (gradle_cfg_path )
657
+ for line in f .readlines ():
658
+ line_str = line .strip ()
659
+ pattern = r'applicationId[ \t]+"(.*)"'
660
+ match = re .match (pattern , line_str )
661
+ if match :
662
+ package = match .group (1 )
663
+ break
664
+
665
+ if package is None :
666
+ # get package name from AndroidManifest.xml
754
667
package = self ._xml_attr (manifest_path , 'AndroidManifest.xml' , 'manifest' , 'package' )
755
668
756
669
activity_name = self ._xml_attr (manifest_path , 'AndroidManifest.xml' , 'activity' , 'android:name' )
0 commit comments