Skip to content

Commit 802e261

Browse files
author
Bin Zhang
committed
Merge pull request cocos2d#149 from toriumi0118/dev
Enable to [cocos run -p android] for Android Studio by mac.
2 parents b04c323 + e9c840d commit 802e261

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ plugins/project_compile/build_web/bin
5151
plugins/plugin_jscompile/bin
5252
version.json
5353
v*-console-*.zip
54+
55+
# vim
56+
*~

bin/cocos.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@ def output_for(command, verbose):
9999

100100
raise CCPluginError(message)
101101

102+
@staticmethod
103+
def convert_path_to_cmd(path):
104+
""" Convert path which include space to correct style which bash(mac) and cmd(windows) can treat correctly.
105+
106+
eg: on mac: convert '/usr/xxx/apache-ant 1.9.3' to '/usr/xxx/apache-ant\ 1.9.3'
107+
eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to '"c:\apache-ant 1.9.3\bin"'
108+
"""
109+
ret = path
110+
if os_is_mac():
111+
ret = path.replace("\ ", " ").replace(" ", "\ ")
112+
113+
if os_is_win32():
114+
ret = "\"%s\"" % (path.replace("\"", ""))
115+
116+
# print("!!!!! Convert %s to %s\n" % (path, ret))
117+
return ret
118+
119+
@staticmethod
120+
def convert_path_to_python(path):
121+
""" COnvert path which include space to correct style which python can treat correctly.
122+
123+
eg: on mac: convert '/usr/xxx/apache-ant\ 1.9.3' to '/usr/xxx/apache-ant 1.9.3'
124+
eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to 'c:\apache-ant 1.9.3\bin'
125+
"""
126+
ret = path
127+
if os_is_mac():
128+
ret = path.replace("\ ", " ")
129+
130+
if os_is_win32():
131+
ret = ret.replace("\"", "")
132+
133+
# print("!!!!! Convert %s to %s\n" % (path, ret))
134+
return ret
102135

103136
#
104137
# Plugins should be a sublass of CCPlugin
@@ -257,7 +290,7 @@ def select_default_android_platform(min_api_level):
257290
sdk_root = check_environment_variable('ANDROID_SDK_ROOT')
258291
platforms_dir = os.path.join(sdk_root, "platforms")
259292
if os.path.isdir(platforms_dir):
260-
for num in range (min_api_level, 19+1):
293+
for num in range (min_api_level, 21):
261294
android_platform = 'android-%s' % num
262295
if os.path.isdir(os.path.join(platforms_dir, android_platform)):
263296
Logging.info('%s is found' % android_platform)

plugins/project_compile/build_android.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,6 @@ def __init__(self, verbose, cocos_root, app_android_root, no_res, proj_obj):
3939
def _run_cmd(self, command):
4040
cocos.CMDRunner.run_cmd(command, self._verbose)
4141

42-
def _convert_path_to_cmd(self, path):
43-
""" Convert path which include space to correct style which bash(mac) and cmd(windows) can treat correctly.
44-
45-
eg: on mac: convert '/usr/xxx/apache-ant 1.9.3' to '/usr/xxx/apache-ant\ 1.9.3'
46-
eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to '"c:\apache-ant 1.9.3\bin"'
47-
"""
48-
ret = path
49-
if cocos.os_is_mac():
50-
ret = path.replace("\ ", " ").replace(" ", "\ ")
51-
52-
if cocos.os_is_win32():
53-
ret = "\"%s\"" % (path.replace("\"", ""))
54-
55-
# print("!!!!! Convert %s to %s\n" % (path, ret))
56-
return ret
57-
58-
def _convert_path_to_python(self, path):
59-
""" COnvert path which include space to correct style which python can treat correctly.
60-
61-
eg: on mac: convert '/usr/xxx/apache-ant\ 1.9.3' to '/usr/xxx/apache-ant 1.9.3'
62-
eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to 'c:\apache-ant 1.9.3\bin'
63-
"""
64-
ret = path
65-
if cocos.os_is_mac():
66-
ret = path.replace("\ ", " ")
67-
68-
if cocos.os_is_win32():
69-
ret = ret.replace("\"", "")
70-
71-
# print("!!!!! Convert %s to %s\n" % (path, ret))
72-
return ret
7342

7443
def _parse_cfg(self):
7544
self.cfg_path = os.path.join(self.app_android_root, BUILD_CFIG_FILE)
@@ -220,7 +189,7 @@ def update_lib_projects(self, sdk_root, sdk_tool_path, android_platform):
220189
if os.path.isdir(abs_lib_path):
221190
api_level = self.check_android_platform(sdk_root, android_platform, abs_lib_path, True)
222191
str_api_level = "android-" + str(api_level)
223-
command = "%s update lib-project -p %s -t %s" % (self._convert_path_to_cmd(sdk_tool_path), abs_lib_path, str_api_level)
192+
command = "%s update lib-project -p %s -t %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), abs_lib_path, str_api_level)
224193
self._run_cmd(command)
225194

226195
def get_target_config(self, proj_path):
@@ -263,7 +232,7 @@ def check_android_platform(self, sdk_root, android_platform, proj_path, auto_sel
263232
raise cocos.CCPluginError("Can't find right android-platform for project : \"%s\". The android-platform should be equal/larger than %d" % (proj_path, min_platform))
264233

265234
platform_path = "android-%d" % ret
266-
ret_path = os.path.join(self._convert_path_to_python(sdk_root), "platforms", platform_path)
235+
ret_path = os.path.join(cocos.CMDRunner.convert_path_to_python(sdk_root), "platforms", platform_path)
267236
if not os.path.isdir(ret_path):
268237
raise cocos.CCPluginError("The directory \"%s\" can't be found in android SDK" % platform_path)
269238

@@ -280,7 +249,7 @@ def do_build_apk(self, sdk_root, ant_root, android_platform, build_mode, output_
280249

281250
# update project
282251
str_api_level = "android-" + str(api_level)
283-
command = "%s update project -t %s -p %s" % (self._convert_path_to_cmd(sdk_tool_path), str_api_level, app_android_root)
252+
command = "%s update project -t %s -p %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), str_api_level, app_android_root)
284253
self._run_cmd(command)
285254

286255
# update lib-projects
@@ -304,7 +273,7 @@ def do_build_apk(self, sdk_root, ant_root, android_platform, build_mode, output_
304273
# invoke custom step: pre-ant-build
305274
self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_ANT_BUILD, target_platform, args_ant_copy)
306275

307-
command = "%s clean %s -f %s -Dsdk.dir=%s" % (self._convert_path_to_cmd(ant_path), build_mode, buildfile_path, self._convert_path_to_cmd(sdk_root))
276+
command = "%s clean %s -f %s -Dsdk.dir=%s" % (cocos.CMDRunner.convert_path_to_cmd(ant_path), build_mode, buildfile_path, cocos.CMDRunner.convert_path_to_cmd(sdk_root))
308277
self._run_cmd(command)
309278

310279
# invoke custom step: post-ant-build
@@ -401,7 +370,7 @@ def _sign_release_apk(self, unsigned_path, signed_path):
401370

402371
def _zipalign_apk(self, apk_file, aligned_file, sdk_root):
403372
align_path = os.path.join(sdk_root, "tools", "zipalign")
404-
align_cmd = "%s 4 %s %s" % (self._convert_path_to_cmd(align_path), apk_file, aligned_file)
373+
align_cmd = "%s 4 %s %s" % (cocos.CMDRunner.convert_path_to_cmd(align_path), apk_file, aligned_file)
405374
if os.path.exists(aligned_file):
406375
os.remove(aligned_file)
407376
self._run_cmd(align_cmd)

plugins/project_deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def deploy_android(self, dependencies):
116116
compile_dep = dependencies['compile']
117117
apk_path = compile_dep.apk_path
118118
sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
119-
adb_path = os.path.join(sdk_root, 'platform-tools', 'adb')
119+
adb_path = cocos.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
120120

121121
#TODO detect if the application is installed before running this
122122
adb_uninstall = "%s uninstall %s" % (adb_path, self.package)

plugins/project_run/project_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def run_android_device(self, dependencies):
8080
return
8181

8282
sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
83-
adb_path = os.path.join(sdk_root, 'platform-tools', 'adb')
83+
adb_path = cocos.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
8484
deploy_dep = dependencies['deploy']
8585
startapp = "%s shell am start -n \"%s/%s\"" % (adb_path, deploy_dep.package, deploy_dep.activity)
8686
self._run_cmd(startapp)

0 commit comments

Comments
 (0)