请问下jsb绑定如何在模拟器环境使用

  按照官网JSB自动绑定教程,我已经实现了并且在安卓真机上正常使用了,但调试太麻烦了,我想可以用模拟器运行然后断点调试。

  是不是要定制引擎,重新 编译一个模拟器exe?

  重新 编译一个模拟器exe的话 ,应该需要?在scripting/js-bindings/manual/jsb_module_register.cpp 中 加入

#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_test_auto.hpp"
se->addRegisterCallback(register_all_cocos2dx_test);// register test

  Andorid.mk要不要改?要改的话是改

D:\ProgramFiles\CocosDashboard_1.0.20\resources\.editors\Creator\2.4.6\resources\cocos2d-x\cocos\Android.mk

这个Android.mk吗?

是的,需要重新编译模拟器

1赞

记录个问题及解决方法
在这之前要注意官方文档的一句话!
  注意 :如果是从编辑器拷贝出来的内置 cocos2d-x 目录,可以跳过该步骤 引擎定制工作流程---- 定制 Cocos2d-x 引擎---- 初始化

问题: gulp init 失败
  下载文件失败(<gitlab访问不了,github网络波动>,自己手动下载 )

    1.下载cocos2d-x-lite-external(gitee | github)文件对应版本(gitee: (切分支2.x–>克隆/下载->下载zip)

        将下载到的zip文件重命名v24-6.zip为 保存到D:\custom\2.4.6\cocos2d-x\文件夹(自定义cocos2d-x引擎目录)下

        更改download-deps.py文件,不让它下载

#!/usr/bin/env python
#coding=utf-8
#
# ./download-deps.py
#

        # 文件名称v24-6.zip
        # zip解压位置 工作目录/cocos2d-x-lite-external/24-6/v24-6.zip
        
        # mirror_repo_url = "https://gitlab.cocos.net/publics/%s/-/archive/%s/%s-%s.zip" % (self._repo_name, self._current_version, self._repo_name, self._current_version)
        更改1
        mirror_repo_url = "" # 用不到,写意思意思   
        
        更改2
        # if mirror is None:
        #     self._url = select_fastest_url([self._url, mirror_repo_url])
        # elif mirror == "gitlab":
        #     self._url = mirror_repo_url
        self._url = mirror_repo_url
        
    def run(self, workpath, folder_for_extracting, remove_downloaded, force_update, download_only):
        ...
        更改3
        # self.download_zip_file() // 注释掉,改为手动gitee下载zip,更名为v24-6.zip 保存在\custom\2.4.6\resources\cocos2d-x\下面

    2.git submodule update失败

         手动下载 bindings-generator ( github)(Code->Download ZIP),下载好后解压放到D:\custom\2.4.6\cocos2d-x\tools\bindings-generator下
           这个不是分支,gitee上也没有镜像,只能到github 上下载(具体位置: engine-native/tools/bindings-generator @ ff32cff)。旧的版本JSB自动绑定有问题。

         手动下载 cocos2d-console (github)(Code->Download ZIP),下载好后解压放到D:\custom\2.4.6\cocos2d-x\tools\cocos2d-console下
           试了下使用这(gitee)(不切分支–>克隆/下载->下载zip)也可以但为了跟上面bindings-generator保持一致,也到github上下载(具体位置: engine-native/tools/cocos2d-console @ 29b9243)

        更改gulpfile.js文件,不让它git submodule update

gulp.task('init', function(cb) {
    execSync('python download-deps.py --remove-download no');
    // execSync('git submodule update --init');
    execSync('python download-bin.py --remove-download no', './tools/cocos2d-console');
    cb();
});

    3. 改好后文件后 重新执行命令

gulp init

        下载 creator-console-2.zip(version.json和plugins 的压缩包 42.9MB) 也可能出错。。我一共下过5次<失败就再次gulp init>,成功过两次,嫌下载慢或老失败,可以参照 1 改download-bin.py文件。

  • 出现Finished,到这里初始化完成了
D:\ProgramFiles\CocosDashboard_1.0.20\resources\.editors\Creator\custom\engine-native>gulp init
[09:17:29] Using gulpfile D:\ProgramFiles\CocosDashboard_1.0.20\resources\.editors\Creator\custom\engine-native\gulpfile.js
[09:17:29] Starting 'init'...
=======================================================
==> Prepare to download external libraries!
==> version file doesn't exist
==> Extracting files, please wait ...
==> Extraction done!
==> Cleaning cocos2d-x/external folder ...
==> Copying files...
==> Cleaning...
=======================================================
==> Prepare to download console binaries!
==> version file doesn't exist
==> Unrecognized zip format from your local 'creator-console-2.zip' file!
==> Download it from internet again, please wait...
==> Ready to download 'creator-console-2.zip' from 'https://github.com/cocos2d/console-binary/archive/creator-console-2.zip'
==> WARNING: Couldn't grab the file size from remote, use 'zip_file_size' section in 'D:\ProgramFiles\CocosDashboard_1.0.20\resources\.editors\Creator\custom\engine-native\tools\cocos2d-console\config.json'
==> Start to download, please wait ...
 ==> Downloading finished!al: 45045K, Percent: 97.31%, Speed: 997.43 KB/S
==> Extracting files, please wait ...
==> Extraction done!
==> Copying files...
==> Cleaning...
[09:19:08] Finished 'init' after 1.65 min

  说下 gulp gen-simulator 命令,这个开启gulp 任务,实际上是调用你电脑上安装的vs2017 编译 simulator.exe的,在使用这个指令之前,最好保证vs2017 调试运行项目成功。对于我这种几乎没怎么使用过vs2017的人来说。。。
  1.解决方案,simulator.sln(D: \2.4.6\cocos2d-x\custom\cocos2d-x<定制cocos2d-x引擎位置>\tools\simulator\frameworks\runtime-src\proj.win32\simulator.sln)。安装好vs2017后,可以通过双击 simulator.sln ,直接用vs2017打开解决方案。
  2. 没安装windwin SDK的话会报错,解决方法
  3. 调试运行没问题后(运行模拟器黑窗口),将自动绑定相关的代码加到工程里。拿官方自动绑定文档那个示例来说,就添加四个文件( 源文件: ABCJSBBridge.cpp、ABCJSBBridge.h jsb绑定文件: jsb_cocos2dx_test_auto.cpp、jsb_cocos2dx_test_auto.hpp)。在解决方案资源管理器中,libcocos2d(第一个)->右键菜单-> 添加->现有项 (选择那四个文件 ctrl和shift可以多选)。 官方文档示例ABCJSBBridge.cpp、ABCJSBBridge.h 是放在cocos/test文件夹下的,你的如果不是放在cocos文件夹下,可能找不到。 可以在vs中顶部菜单栏 项目->属性->C/C+±>附加包含目录->编辑-> ABCJSBBridge.cpp所在目录 。就放在cocos文件夹下就不要管,项目已经添加了 $(ProjectDir)…\cocos
  4.vs调试运行没问题,就可以到自定义引擎目录下 gulp gen-simulator 了,成功后会发现 模拟器路径(D: \2.4.6\cocos2d-x\custom\cocos2d-x<定制cocos2d-x引擎位置>\simulator\win32)下内容变了。

1赞

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。