diff --git a/README.md b/README.md index 02a33216..c5bca8e9 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ $ cocos new MyGame -l cpp -p org.cocos2d.mygame $ cd MyGame -# Will deploy the project to device and run it -$ cocos run -p android +# Will deploy the project to device and run it (if '-bundle' is appended to build mode [release/debug], it'll create app bundle. otherwise, apk) +$ cocos run -p android [-m release/debug/release-bundle/debug-bundle] ``` diff --git a/plugins/plugin_compile/build_android.py b/plugins/plugin_compile/build_android.py index e89d4a19..2523f066 100755 --- a/plugins/plugin_compile/build_android.py +++ b/plugins/plugin_compile/build_android.py @@ -355,7 +355,7 @@ def check_android_platform(self, sdk_root, android_platform, proj_path): return ret - def gradle_build_apk(self, mode, android_platform, compile_obj): + def gradle_build_apk(self, mode, android_platform, compile_obj, bundle): # check the compileSdkVersion & buildToolsVersion check_file = os.path.join(self.app_android_root, 'app', 'build.gradle') f = open(check_file) @@ -401,8 +401,9 @@ def gradle_build_apk(self, mode, android_platform, compile_obj): raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_GRALEW_NOT_EXIST_FMT', gradle_path), cocos.CCPluginError.ERROR_PATH_NOT_FOUND) + build = 'bundle' if bundle else 'assemble' mode_str = 'Debug' if mode == 'debug' else 'Release' - cmd = '"%s" --parallel --info assemble%s' % (gradle_path, mode_str) + cmd = '"%s" --parallel --info %s%s' % (gradle_path, build, mode_str) if self.gradle_support_ndk: add_props = { @@ -487,7 +488,7 @@ def _get_build_arch(self, param_of_appabi): return self.LuaBuildArch.UNKNOWN - def do_build_apk(self, mode, no_apk, no_sign, output_dir, custom_step_args, android_platform, compile_obj): + def do_build_apk(self, mode, no_apk, no_sign, output_dir, custom_step_args, android_platform, compile_obj, bundle): assets_dir = os.path.join(self.app_android_root, "app", "assets") project_name = None setting_file = os.path.join(self.app_android_root, 'settings.gradle') @@ -556,10 +557,12 @@ def do_build_apk(self, mode, no_apk, no_sign, output_dir, custom_step_args, andr self._gather_sign_info() # build apk - self.gradle_build_apk(mode, android_platform, compile_obj) + self.gradle_build_apk(mode, android_platform, compile_obj, bundle) # copy the apk to output dir - if output_dir: + if bundle: + return + elif output_dir: # support generate unsigned apk if mode == "release" and no_sign: apk_name = '%s-%s-unsigned.apk' % (project_name, mode) diff --git a/plugins/plugin_compile/project_compile.py b/plugins/plugin_compile/project_compile.py index ebbfda06..6a63bb23 100644 --- a/plugins/plugin_compile/project_compile.py +++ b/plugins/plugin_compile/project_compile.py @@ -123,10 +123,12 @@ def _add_custom_options(self, parser): def _check_custom_options(self, args): # get the mode parameter - available_modes = [ 'release', 'debug' ] + available_modes = [ 'release', 'debug', 'release-bundle', 'debug-bundle' ] self._mode = self.check_param(args.mode, 'debug', available_modes, MultiLanguage.get_string('COMPILE_ERROR_WRONG_MODE_FMT', available_modes)) + self._bundle = True if self._mode.find('bundle') != -1 else False + self._mode = self._mode.split('-')[0] # android arguments available_build_types = [ 'cmake','ndk-build', 'none'] @@ -537,7 +539,7 @@ def build_android(self): # build apk if not self._no_apk: cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILD_APK')) - self.apk_path = builder.do_build_apk(build_mode, self._no_apk, self._no_sign, output_dir, self._custom_step_args, self._ap, self) + self.apk_path = builder.do_build_apk(build_mode, self._no_apk, self._no_sign, output_dir, self._custom_step_args, self._ap, self, self._bundle) self.android_package, self.android_activity = builder.get_apk_info() cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILD_SUCCEED')) diff --git a/plugins/plugin_deploy.py b/plugins/plugin_deploy.py index 63bb7f0c..7f28514f 100644 --- a/plugins/plugin_deploy.py +++ b/plugins/plugin_deploy.py @@ -154,6 +154,8 @@ def deploy_android(self, dependencies): cocos.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_INSTALLING_APK')) compile_dep = dependencies['compile'] + if compile_dep._bundle: + return self.package = compile_dep.android_package self.activity = compile_dep.android_activity apk_path = compile_dep.apk_path diff --git a/plugins/plugin_run/project_run.py b/plugins/plugin_run/project_run.py index 706fb45b..61abe02b 100644 --- a/plugins/plugin_run/project_run.py +++ b/plugins/plugin_run/project_run.py @@ -221,12 +221,12 @@ def run_mac(self, dependencies): self._run_with_desktop_options(launch_macapp) def run_android_device(self, dependencies): - if not self._platforms.is_android_active(): + deploy_dep = dependencies['deploy'] + if not self._platforms.is_android_active() or not hasattr(deploy_dep, 'package'): return sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT') adb_path = cocos.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb')) - deploy_dep = dependencies['deploy'] startapp = "%s shell am start -n \"%s/%s\"" % (adb_path, deploy_dep.package, deploy_dep.activity) self._run_cmd(startapp) pass