原生包启动报错

版本号:

 V 2.4.3

日志

 2021-03-30 19:41:10.625 9084-9101/? E/jswrapper: ScriptEngine::onGetStringFromFile stream not found, possible missing file.

2021-03-30 19:41:10.627 9084-9101/? E/jswrapper: ScriptEngine::runScript script stream, buffer is empty!
2021-03-30 19:41:10.629 9084-9101/? E/jswrapper: [ERROR] Failed to invoke require, location: D:/cocosN/CocosDashboard/resources/.editors/Creator/2.4.3/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:300

哪位大佬帮忙看看 实在找不到方向了

看着跟我刚刚的问题很像。是不是JAVA 调用js 找不到文件还是怎么了

没有调用原生

看看这个,你打包的时候把原先项目打包出来的安卓包删掉再打包新的

原来的整个build目录都是删了重新编译的,还是启动黑屏,并且用Cocos的模拟器运行直接闪退

那我不懂了。没有遇到这个情况。

好的 谢谢你

自己顶一下 哪位大佬帮忙指导一下

看一下,项目模块是不是有需要的没有勾选,建议全选试一下

image
这个我也试过 但也是失败的

好吧 之前遇到类似的问题 我这边就是模块的问题。。

嗯 好的 谢谢你

楼主检查一下这两个文件吧:

  • jsb_run_script(“jsb-adapter/jsb-builtin.js”);
  • jsb_run_script(“main.js”);
    附上2.4.4C++源码:
bool AppDelegate::applicationDidFinishLaunching()
{
    se::ScriptEngine *se = se::ScriptEngine::getInstance();
    
    jsb_set_xxtea_key("478bc01f-edfc-40");
    jsb_init_file_operation_delegate();
    
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
    // Enable debugger here
    jsb_enable_debugger("0.0.0.0", 6086, false);
#endif
    
    se->setExceptionCallback([](const char *location, const char *message, const char *stack) {
        // Send exception information to server like Tencent Bugly.
        cocos2d::log("\nUncaught Exception:\n - location :  %s\n - msg : %s\n - detail : \n      %s\n", location, message, stack);
    });
    
    jsb_register_all_modules();
    
    se->start();
    
    se::AutoHandleScope hs;
    jsb_run_script("jsb-adapter/jsb-builtin.js");
    jsb_run_script("main.js");
    
    se->addAfterCleanupHook([]() {
        JSBClassType::destroy();
    });
    
    return true;
}
bool jsb_run_script(const std::string& filePath, se::Value* rval/* = nullptr */)
{
    se::AutoHandleScope hs;
    return se::ScriptEngine::getInstance()->runScript(filePath, rval);
}
bool ScriptEngine::runScript(const std::string& path, Value* ret/* = nullptr */)
    {
        assert(!path.empty());
        assert(_fileOperationDelegate.isValid());

        std::string scriptBuffer = _fileOperationDelegate.onGetStringFromFile(path);

        if (!scriptBuffer.empty())
        {
            return evalString(scriptBuffer.c_str(), scriptBuffer.length(), ret, path.c_str());
        }

        SE_LOGE("ScriptEngine::runScript script %s, buffer is empty!\n", path.c_str());
        return false;
    }
delegate.onGetStringFromFile = [](const std::string& path) -> std::string{
            assert(!path.empty());

            std::string byteCodePath = removeFileExt(path) + BYTE_CODE_FILE_EXT;
            if (FileUtils::getInstance()->isFileExist(byteCodePath)) {
                Data fileData = FileUtils::getInstance()->getDataFromFile(byteCodePath);

                uint32_t dataLen;
                uint8_t* data = xxtea_decrypt((uint8_t*)fileData.getBytes(), (uint32_t)fileData.getSize(), (uint8_t*)xxteaKey.c_str(), (uint32_t)xxteaKey.size(), &dataLen);

                if (data == nullptr) {
                    SE_REPORT_ERROR("Can't decrypt code for %s", byteCodePath.c_str());
                    return "";
                }

                if (ZipUtils::isGZipBuffer(data,dataLen)) {
                    uint8_t* unpackedData;
                    ssize_t unpackedLen = ZipUtils::inflateMemory(data, dataLen,&unpackedData);
                    if (unpackedData == nullptr) {
                        SE_REPORT_ERROR("Can't decrypt code for %s", byteCodePath.c_str());
                        return "";
                    }

                    std::string ret(reinterpret_cast<const char*>(unpackedData), unpackedLen);
                    free(unpackedData);
                    free(data);

                    return ret;
                }
                else {
                    std::string ret(reinterpret_cast<const char*>(data), dataLen);
                    free(data);
                    return ret;
                }
            }

            if (FileUtils::getInstance()->isFileExist(path)) {
                return FileUtils::getInstance()->getStringFromFile(path);
            }
            else {
                SE_LOGE("ScriptEngine::onGetStringFromFile %s not found, possible missing file.\n", path.c_str());
            }
            return "";
        };

你好 能具体说说吗,没怎么看懂,谢谢你

我根据的你抛错信息,找到调用的源头,最终是因为我指出的两个文件导致的抛错。

这两个不是引擎自带的文件嘛

你的抛错

ScriptEngine::onGetStringFromFile stream not found, possible missing file.

结合代码

SE_LOGE("ScriptEngine::onGetStringFromFile %s not found, possible missing file.\n", path.c_str());
  • c++的c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同

所以你出问题的文件路径是:stream。

对 我定位到这个脚本了

大佬 麻烦继续指导一下