Quick-cocos2d-x的热更新机制实现(终极版2)(更新3.3版本)

朋友我按照你的建议重新做了一遍,还是一样的问题
特别是如果是如果把lib/launcher.png 应该放入 res目录下
CCLuaLoadChunksFromZIP(“res/lib/launcher.zip”) 就必须要加上res前缀,否则提示找不到文件

我的Q2D版本号是最新的2.2.5,不知道这个版本你试过没有?
报错详情见附件

你AppDelegate.cpp 是按照我的方法加的吗?
还有launcher.zip必须是用quick提供的工具打包

还有 你这是在windows上跑的化 你需要在launcher目录下
function LauncherScene:ctor()
self._path = Launcher.writablePath … “upd/”

if (Launcher.platform ~= "android" and Launcher.platform ~= "ios") then
    CCFileUtils:sharedFileUtils():addSearchPath(self._path)
    CCFileUtils:sharedFileUtils():addSearchPath("res/")
end

self._textLabel = CCLabelTTF:create(STR_LCHER_HAS_UPDATE, LCHER_FONT, 20)
self._textLabel:setColor(ccc3(255, 255, 255))
self._textLabel:setPosition(Launcher.cx, Launcher.cy - 60)
self:addChild(self._textLabel)

Launcher.performWithDelayGlobal(function()
    if (Launcher.platform == "android" or Launcher.platform == "ios") then
        Launcher.initPlatform(lcher_handler(self, self._initPlatformResult))
    else
        enter_game()
    end
end, 0.1)

end

加上红色部分代码

1:是的
2:是的
3:你加红的那段代码,下载过来的代码已经添加了。
4:朋友,你能发一个能跑的测试工程给我吗?我全程按照你的步骤下来,没道理卡在一个地方啊。。

这个帖子里面的都是测试工程,我跑通了才上传的 使用的是quick 2.2.5 windows mac ios android 上都测试过了。

报错的问题解决了,是因为我用打包工具的时候,没有把目录launcher给包括进去,所以导致找不到。。
给出可以跑的例子,新手朋友可以下载过来直接进入更新界面
按照自己实际需求修改更新代码。。

void AppDelegate::initResourcePath()
{
    CCFileUtils* sharedFileUtils = CCFileUtils::sharedFileUtils();
    //设置SearchPaths
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    std::vector oldSearchPaths = sharedFileUtils->getSearchPaths();
    std::vector tempPaths(oldSearchPaths);
    std::vector searchPaths;
    searchPaths.push_back(sharedFileUtils->getWritablePath() + "upd/");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    searchPaths.push_back("res/");
#else
    std::string strBasePath = getAppBaseResourcePath();
    searchPaths.push_back(strBasePath);
    searchPaths.push_back(strBasePath + "res/");
#endif
    for (int i = 0; i < tempPaths.size(); ++i) {
        searchPaths.push_back(tempPaths);    //这里报错!!no matching member function for call to 'push_back'
    }
    sharedFileUtils->setSearchPaths(searchPaths);
#else
    sharedFileUtils->addSearchPath("res/");
#endif
}



```

解决了,改成searchPaths.push_back(tempPaths*); *

Cocos2d: LOAD LUA FILE: /var/mobile/Applications/A01B8F63-850D-4497-A4FD-23E7FAF144BC/updtest.app/scripts/main.lua
Cocos2d: ------------------------------------------------
Cocos2d: lua_loadChunksFromZIP() - load zip file: /var/mobile/Applications/A01B8F63-850D-4497-A4FD-23E7FAF144BC/updtest.app/lib/launcher.zip
Cocos2d: lua_loadChunksFromZIP() - loaded chunks count: 3
Cocos2d:  ----------------------------------------
Cocos2d:  LUA ERROR: :0: attempt to call global 'printError' (a nil value)

Cocos2d:  
stack traceback:
    : in function 'callStaticMethod'
    : in function ''
    : in function 'initPlatform'
    : in function ''
    : in main chunk
Cocos2d:  ----------------------------------------



```


接下来IPHONE5真机调试报这错了= =

谢谢反馈, 需要把printError 修改成print

mark mark

在安卓真机测试时报这错

08-21 15:08:19.238: E/AndroidRuntime(14298): FATAL EXCEPTION: GLThread 5904
08-21 15:08:19.238: E/AndroidRuntime(14298): Process: com.yygc.updtest, PID: 14298
08-21 15:08:19.238: E/AndroidRuntime(14298): java.lang.NoSuchMethodError: no static method with name='getAppBaseResourcePath' signature='()Ljava/lang/String;' in class Lcom/yygc/updtest/Updtest;
08-21 15:08:19.238: E/AndroidRuntime(14298):     at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
08-21 15:08:19.238: E/AndroidRuntime(14298):     at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:72)
08-21 15:08:19.238: E/AndroidRuntime(14298):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
08-21 15:08:19.238: E/AndroidRuntime(14298):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)


```

这个是需要java层实现的这个方法, 首先你看AppPlatform.cpp 中#define GAME_CLASS_NAME “com/xxoo/xxoo/luajavabridge/Luajavabridge” 需要替换成你自己的jiava工程目录结构, 在Luajavabridge.java 中实现
static String getAppBaseResourcePath() 这个方法就可以了。如果你嫌弃麻烦也可以在AppPlatform.cpp 中getAppBaseResourcePath方法的 android部分直接返回指定path。

确实有点麻烦 囧
不会java
能请教下
static String getAppBaseResourcePath() 在java中如何写么

首先你得去学习C++调java相关的知识。实现是很简单的
再有 如果你没有做初次安装把assert目录下的资源拷贝到sdcard上去的话,就可以注释下面代码中红色的2行代码, 蓝色为修改后的路径。

void AppDelegate::initResourcePath()
{
CCFileUtils* sharedFileUtils = CCFileUtils::sharedFileUtils();
//设置SearchPaths
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
std::vectorstd::string oldSearchPaths = sharedFileUtils->getSearchPaths();
std::vectorstd::string tempPaths(oldSearchPaths);
std::vectorstd::string searchPaths;
searchPaths.push_back(sharedFileUtils->getWritablePath() + “upd/”);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
searchPaths.push_back(“res/”);
#else
//std::string strBasePath = getAppBaseResourcePath();
//searchPaths.push_back(strBasePath);
searchPaths.push_back("/assets/res/");
#endif
for (int i = 0; i < tempPaths.size(); ++i) {
searchPaths.push_back(tempPaths*);
}

sharedFileUtils->setSearchPaths(searchPaths);

#else
sharedFileUtils->addSearchPath(“res/”);
#endif

}*

多谢指点 我直接改成 sharedFileUtils->getWritablePath() + “res/”

在launcher模块中。以下代码需要怎么改呢,不改貌似还是调用JAVA

if Launcher.platform == "android" then
    Launcher.javaClassName = "com/yygc/xxx/xxx"  
    Launcher.luaj = {}
    function Launcher.luaj.callStaticMethod(className, methodName, args, sig)
        return CCLuaJavaBridge.callStaticMethod(className, methodName, args, sig)


```

:14::14::14::14::14::14::14::14:

利用闲暇时间学了下JAVA基础,看了下JNIHELP源码,终于自己实现了,感谢指点

这个是lua 层直接调用java的方法,其实原理还是lua调用c++ 然后 C++再调用java,只是c++ 调用java已经被framework封装好了。