Example #1
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        output_dir = self._output_dir
        if self._project._is_script_project():
            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks',
                                          'cocos2d-x')
            else:
                cocos_root = os.path.join(
                    project_dir, 'frameworks',
                    '%s-bindings' % self._project.get_language(), 'cocos2d-x')
        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root,
                                 project_android_dir, self._no_res,
                                 self._project)

        args_ndk_copy = self._custom_step_args.copy()
        target_platform = self._platforms.get_current_platform()

        if not self._project._is_script_project(
        ) or self._project._is_native_support():
            if self._ndk_mode != "none":
                # build native code
                cocos.Logging.info("building native")
                ndk_build_param = "-j%s" % self._jobs
                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD,
                    target_platform, args_ndk_copy)
                builder.do_ndk_build(ndk_build_param, self._ndk_mode)
                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_POST_NDK_BUILD,
                    target_platform, args_ndk_copy)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, self._ap,
                                             build_mode, output_dir,
                                             self._custom_step_args)

        cocos.Logging.info("build succeeded.")
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        if self._project._is_script_project():
            if build_mode == 'debug':
                output_dir = os.path.join(
                    project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG,
                    'android')
            else:
                output_dir = os.path.join(
                    project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE,
                    'android')

            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks',
                                          'cocos2d-x')
            else:
                cocos_root = os.path.join(
                    project_dir, 'frameworks',
                    '%s-bindings' % self._project.get_language(), 'cocos2d-x')

        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')
            output_dir = os.path.join(project_dir,
                                      CCPluginCompile.OUTPUT_DIR_NATIVE,
                                      build_mode, 'android')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        ndk_root = cocos.check_environment_variable('NDK_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root,
                                 project_android_dir, self._no_res)

        # build native code
        cocos.Logging.info("building native")
        ndk_build_param = "-j%s" % self._jobs
        builder.do_ndk_build(ndk_root, ndk_build_param, build_mode)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, self._ap,
                                             build_mode, output_dir)

        cocos.Logging.info("build succeeded.")
Example #3
0
def build_android(current_dir,configfile,ndk_build_param,android_platform,build_mode):
    cocos_root = os.path.join(current_dir, "../../cocos2d-x")
        # 需要用到的三个环境变量
    ant_root = check_environment_variable('ANT_ROOT')
    ndk_root = check_environment_variable('NDK_ROOT')
    sdk_root = check_environment_variable('ANDROID_SDK_ROOT')

    print("ANT_ROOT:"+ant_root)
    print("NDK_ROOT:"+ndk_root)
    print("ANDROID_SDK_ROOT:"+sdk_root)

    app_android_root = current_dir
        
    if build_mode is None:
          build_mode = 'debug'
    elif build_mode != 'release':
        build_mode = 'debug'

    project_dir = app_android_root

    #输出目录
    if build_mode == 'debug':
        output_dir = os.path.join(project_dir, OUTPUT_DIR_NATIVE, 'android')
    else:
        output_dir = os.path.join(project_dir, OUTPUT_DIR_SCRIPT_RELEASE, 'android')

  
    #导入编译模块
    _no_res=False
    from build_android import AndroidBuilder
    builder = AndroidBuilder(configfile,cocos_root,app_android_root)

    # build native code
    print("start building native")
    builder.do_ndk_build(ndk_root,ndk_build_param, build_mode)

    # build apk
    print("start building apk:android_platform:",android_platform)
    if android_platform is not None:
        android_platform_int=int(android_platform)
        apk_path = builder.do_build_apk(sdk_root,ant_root,android_platform_int, build_mode, output_dir) 

    print("build succeeded.")
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        output_dir = self._output_dir
        if self._project._is_script_project():
            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks' ,'cocos2d-x')
            else:
                cocos_root = os.path.join(project_dir, 'frameworks' ,'%s-bindings' % self._project.get_language(), 'cocos2d-x')
        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root, project_android_dir, self._no_res, self._project)

        args_ndk_copy = self._custom_step_args.copy()
        target_platform = self._platforms.get_current_platform()

        if not self._project._is_script_project() or self._project._is_native_support():
            if self._ndk_mode != "none":
                # build native code
                cocos.Logging.info("building native")
                ndk_build_param = "-j%s" % self._jobs
                self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD, target_platform, args_ndk_copy)
                builder.do_ndk_build(ndk_build_param, self._ndk_mode)
                self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_POST_NDK_BUILD, target_platform, args_ndk_copy)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, self._ap, build_mode, output_dir, self._custom_step_args, self)

        cocos.Logging.info("build succeeded.")
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        if self._project._is_script_project():
            if build_mode == 'debug':
                output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG, 'android')
            else:
                output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE, 'android')

            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks' ,'cocos2d-x')
            else:
                cocos_root = os.path.join(project_dir, 'frameworks' ,'%s-bindings' % self._project.get_language(), 'cocos2d-x')

        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')
            output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_NATIVE, build_mode, 'android')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        ndk_root = cocos.check_environment_variable('NDK_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root, project_android_dir, self._no_res)

        # build native code
        cocos.Logging.info("building native")
        ndk_build_param = "-j%s" % self._jobs
        builder.do_ndk_build(ndk_root, ndk_build_param, build_mode)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, self._ap, build_mode, output_dir) 

        cocos.Logging.info("build succeeded.")
Example #6
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        output_dir = self._output_dir
        if self._project._is_script_project():
            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks',
                                          'cocos2d-x')
            else:
                cocos_root = os.path.join(
                    project_dir, 'frameworks',
                    '%s-bindings' % self._project.get_language(), 'cocos2d-x')
        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root,
                                 project_android_dir, self._no_res,
                                 self._project)

        args_ndk_copy = self._custom_step_args.copy()
        target_platform = self._platforms.get_current_platform()

        # update the project with the android platform
        builder.update_project(sdk_root, self._ap)

        if not self._project._is_script_project(
        ) or self._project._is_native_support():
            if self._ndk_mode != "none":
                # build native code
                cocos.Logging.info("building native")
                ndk_build_param = ["-j%s" % self._jobs]

                if self.app_abi:
                    abi_param = "APP_ABI=\"%s\"" % self.app_abi
                    ndk_build_param.append(abi_param)

                if self.ndk_toolchain:
                    toolchain_param = "NDK_TOOLCHAIN=%s" % self.ndk_toolchain
                    ndk_build_param.append(toolchain_param)

                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD,
                    target_platform, args_ndk_copy)

                modify_mk = False
                app_mk = os.path.join(project_android_dir,
                                      "jni/Application.mk")
                mk_content = None
                if self.cppflags and os.path.exists(app_mk):
                    # record the content of Application.mk
                    f = open(app_mk)
                    mk_content = f.read()
                    f.close()

                    # Add cpp flags
                    f = open(app_mk, "a")
                    f.write("\nAPP_CPPFLAGS += %s" % self.cppflags)
                    f.close()
                    modify_mk = True

                try:
                    builder.do_ndk_build(ndk_build_param, self._ndk_mode)
                except:
                    raise cocos.CCPluginError("Ndk build failed!")
                finally:
                    # roll-back the Application.mk
                    if modify_mk:
                        f = open(app_mk, "w")
                        f.write(mk_content)
                        f.close()

                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_POST_NDK_BUILD,
                    target_platform, args_ndk_copy)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, build_mode,
                                             output_dir,
                                             self._custom_step_args, self)

        cocos.Logging.info("build succeeded.")
Example #7
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        output_dir = self._output_dir
        if self._project._is_script_project():
            if self._project._is_lua_project():
                cocos_root = os.path.join(project_dir, 'frameworks' ,'cocos2d-x')
            else:
                cocos_root = os.path.join(project_dir, 'frameworks' ,'%s-bindings' % self._project.get_language(), 'cocos2d-x')
        else:
            cocos_root = os.path.join(project_dir, 'cocos2d')

        # check environment variable
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
        project_android_dir = self._platforms.project_path()

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, cocos_root, project_android_dir, self._no_res, self._project)

        args_ndk_copy = self._custom_step_args.copy()
        target_platform = self._platforms.get_current_platform()

        # update the project with the android platform
        builder.update_project(sdk_root, self._ap)

        if not self._project._is_script_project() or self._project._is_native_support():
            if self._ndk_mode != "none":
                # build native code
                cocos.Logging.info("building native")
                ndk_build_param = [
                    "-j%s" % self._jobs
                ]

                if self.app_abi:
                    abi_param = "APP_ABI=\"%s\"" % self.app_abi
                    ndk_build_param.append(abi_param)

                if self.ndk_toolchain:
                    toolchain_param = "NDK_TOOLCHAIN=%s" % self.ndk_toolchain
                    ndk_build_param.append(toolchain_param)

                self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD, target_platform, args_ndk_copy)

                modify_mk = False
                app_mk = os.path.join(project_android_dir, "jni/Application.mk")
                mk_content = None
                if self.cppflags and os.path.exists(app_mk):
                    # record the content of Application.mk
                    f = open(app_mk)
                    mk_content = f.read()
                    f.close()

                    # Add cpp flags
                    f = open(app_mk, "a")
                    f.write("\nAPP_CPPFLAGS += %s" % self.cppflags)
                    f.close()
                    modify_mk = True

                try:
                    builder.do_ndk_build(ndk_build_param, self._ndk_mode)
                except:
                    raise cocos.CCPluginError("Ndk build failed!")
                finally:
                    # roll-back the Application.mk
                    if modify_mk:
                        f = open(app_mk, "w")
                        f.write(mk_content)
                        f.close()

                self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_POST_NDK_BUILD, target_platform, args_ndk_copy)

        # build apk
        cocos.Logging.info("building apk")
        self.apk_path = builder.do_build_apk(sdk_root, ant_root, build_mode, output_dir, self._custom_step_args, self)

        cocos.Logging.info("build succeeded.")
    def build_android(self):
        if not self._platforms.is_android_active():
            return

        project_dir = self._project.get_project_dir()
        build_mode = self._mode
        output_dir = self._output_dir

        # get the android project path
        cfg_obj = self._platforms.get_current_config()
        project_android_dir = cfg_obj.proj_path

        ide_name = 'Android Studio'
        cocos.Logging.info(
            MultiLanguage.get_string('COMPILE_INFO_ANDROID_PROJPATH_FMT',
                                     (ide_name, project_android_dir)))

        # Check whether the gradle of the project is support ndk or not
        # Get the engine version of the project
        engine_version_num = self.get_engine_version_num()
        if engine_version_num is None:
            raise cocos.CCPluginError(
                MultiLanguage.get_string(
                    'COMPILE_ERROR_UNKNOWN_ENGINE_VERSION'))

        # Gradle supports NDK build from engine 3.15
        main_ver = engine_version_num[0]
        minor_ver = engine_version_num[1]
        if main_ver > 3 or (main_ver == 3 and minor_ver >= 15):
            gradle_support_ndk = True

        from build_android import AndroidBuilder
        builder = AndroidBuilder(self._verbose, project_android_dir,
                                 self._no_res, self._project, self._mode,
                                 self._build_type, self.app_abi,
                                 gradle_support_ndk)

        args_ndk_copy = self._custom_step_args.copy()
        target_platform = self._platforms.get_current_platform()

        # update the project with the android platform
        builder.update_project(self._ap)

        if not self._project._is_script_project(
        ) or self._project._is_native_support():
            if self._build_type != "none" and not gradle_support_ndk:
                # build native code
                cocos.Logging.info(
                    MultiLanguage.get_string('COMPILE_INFO_BUILD_NATIVE'))
                ndk_build_param = ["-j%s" % self._jobs]

                if self.app_abi:
                    abi_param = "APP_ABI=\"%s\"" % self.app_abi
                    ndk_build_param.append(abi_param)

                if self.ndk_toolchain:
                    toolchain_param = "NDK_TOOLCHAIN=%s" % self.ndk_toolchain
                    ndk_build_param.append(toolchain_param)

                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD,
                    target_platform, args_ndk_copy)

                modify_mk = False
                app_mk = os.path.join(project_android_dir,
                                      "app/jni/Application.mk")

                mk_content = None
                if self.cppflags and os.path.exists(app_mk):
                    # record the content of Application.mk
                    f = open(app_mk)
                    mk_content = f.read()
                    f.close()

                    # Add cpp flags
                    f = open(app_mk, "a")
                    f.write("\nAPP_CPPFLAGS += %s" % self.cppflags)
                    f.close()
                    modify_mk = True

                try:
                    builder.do_ndk_build(ndk_build_param, self._mode,
                                         self._build_type, self)
                except Exception as e:
                    if e.__class__.__name__ == 'CCPluginError':
                        raise e
                    else:
                        raise cocos.CCPluginError(
                            MultiLanguage.get_string(
                                'COMPILE_ERROR_NDK_BUILD_FAILED'),
                            cocos.CCPluginError.ERROR_BUILD_FAILED)
                finally:
                    # roll-back the Application.mk
                    if modify_mk:
                        f = open(app_mk, "w")
                        f.write(mk_content)
                        f.close()

                self._project.invoke_custom_step_script(
                    cocos_project.Project.CUSTOM_STEP_POST_NDK_BUILD,
                    target_platform, args_ndk_copy)

        # 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.android_package, self.android_activity = builder.get_apk_info()

        cocos.Logging.info(
            MultiLanguage.get_string('COMPILE_INFO_BUILD_SUCCEED'))