Cocos Creator 热更新教程

因為使用這個範例已經是好久以前的事,我也沒有記得很清楚,
但我可以確認的是,
這個熱更新是可運行的,
我目前的項目就是用這裡的熱更新方案

所以我建議你可以這樣試試:

自行修改畫面 (例如在畫面上加上版本號)
然後重新打包過一次遠端文件 ( 使用version_generator.js )
再放到你的服務端去,

然後把本地端做一下修改 (把畫面上的版本號改回來)
然後再執行熱更新,
再來在遊戲重啟之後,確認一下畫面是不是已經更新成遠端的版本

更新进度条显示后,服务器的资源文件已经下载到了本地,这个是可以确认的。报错后,重新运行程序,点击按钮找不到table场景。
您的建议的意思,是想验证是不是已经加载了远端下载的版本?无法找到table场景,就可以说明没有找到这个目录吧。
我需要知道的是,我用的模拟器的方式,资源下载到本地后,为什么会报错?报错后重新运行,为什么找不到下载到资源?如果换成build方式,没有任何反应?我跟了好几个版本了,每次提问的时候,官方并没告诉版本有问题,然后过好几天再说是版本的问题,我已经跟进到1.1.1版本了,是不是这个版本还有问题呢?如果我描述的够细致,希望官方技术可以抽出一分钟时间,回答我的疑惑。
@panda@jare

Simulator : Storage path for remote asset : /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/simulator/mac/Simulator.app/Contents/Resources/blackjack-remote-asset
资源下载到了这个目录。
反复删了很多次了,还是报错。如下图
重新运行,找不到table场景。


官方人员可以回复么?

点击上图的的重新打开后,弹出如下的错误:


弹框下面的信息:
Storage path for remote asset : /Users/***/Documents/blackjack-remote-asset
Code: 5
Code: 4
Already up to date with the latest remote version.

模拟器的控制台日志:
Simulator : Storage path for remote asset : /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/simulator/mac/Simulator.app/Contents/Resources/blackjack-remote-asset

这两个地方的Storage path for remote asset不一致。

再次模拟器重新打开,找不到table场景,日志如下:
Regex

Collapse
Simulator : WORKAREA WIDTH 1680.00, HEIGHT 954.00
Simulator : FRAME SCALE = 1.00
Simulator : GLFWError #65544 Happen, Failed to retrieve display name
Simulator :
Simulator : {
Simulator : gl.supports_vertex_array_object: true
Simulator : cocos2d.x.version: cocos2d-x-3.10-lite
Simulator : cocos2d.x.compiled_with_profiler: false
Simulator : gl.version: 2.1 INTEL-10.14.58
Simulator : cocos2d.x.build_type: DEBUG
Simulator : cocos2d.x.build_time: 09:40:13 Jun 7 2016
Simulator : cocos2d.x.compiled_with_gl_state_cache: true
Simulator : gl.max_texture_size: 16384
Simulator : gl.supports_ETC1: false
Simulator : gl.supports_BGRA8888: false
Simulator : gl.supports_PVRTC: false
Simulator : gl.renderer: Intel Iris OpenGL Engine
Simulator : gl.vendor: Intel Inc.
Simulator : gl.max_texture_units: 16
Simulator : gl.supports_OES_packed_depth_stencil: false
Simulator : gl.supports_NPOT: true
Simulator : gl.supports_discard_framebuffer: false
Simulator : gl.supports_OES_depth24: false
Simulator : }
Simulator : Project Config:
Simulator : project dir: /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/simulator/mac/Simulator.app/Contents/Resources/
Simulator : writable path: (PROJDIR)/ Simulator : script file: (PROJDIR)/main.js
Simulator : frame size: 960 x 640
Simulator : frame scale: 1.00
Simulator : show console: NO
Simulator : write debug log: NO ()
Simulator : listen:
Simulator : debugger: none
Simulator : add searching path:
Simulator :
3
Simulator : ------------------------------------------------
2
Simulator : LOAD Js FILE: main.js
Simulator : Cocos2d-JS v3.9
Simulator : iShow!
Simulator : Storage path for remote asset : /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/simulator/mac/Simulator.app/Contents/Resources/blackjack-remote-asset
Simulator : Code: 5
Simulator : Code: 4
Simulator : Already up to date with the latest remote version.

Simulator : ERROR : loadScene: Can not load the scene “table” because it was not in the build settings before playing.

cocos creator1.1.1,21点程序最新。所有的都是最新的了。官方技术大神可以指点下么?

自己关注,希望官方可以看到解决

1赞

继续关注置顶。

windows 例子运行后报错,这是什么鬼 有知道的吗?

我的是mac,看来mac和windows都有错误,知道的大神给指点下吧

build后,不直接点击运行,
main.js加入 :
// 在 main.js 的开头添加如下代码
if (cc.sys.isNative) {
var hotUpdateSearchPaths = cc.sys.localStorage.getItem(‘HotUpdateSearchPaths’);
if (hotUpdateSearchPaths) {
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
}
进入frameworks/runtime-src/proj.ios-mac/下执行tutorial-hot-update.xcodeproj 通过xcode打开工程,报错:
tutorial-hot-update-mobile[9766:367264] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.
在porj.ios-mac/ios/info.list文件加入:
NSAppTransportSecurity

NSAllowsArbitraryLoads


此处论坛帖子把标签过滤了。
重新执行。
build时分为binary/default,调试模式/非调试模式:
这四种组合都可以更新资源到本地,但只有binary/调试模式、default/调试模式这两种组合,点击快速开始按钮可以load到table场景!!!即成功热更新,并成功加载!!!非调试模式无响应!!!
==============
default方式打开工程控制台日志:
{
gl.supports_vertex_array_object: true
cocos2d.x.version: cocos2d-x-3.10-lite
cocos2d.x.compiled_with_profiler: false
gl.version: OpenGL ES 2.0 APPLE-12.0.41
cocos2d.x.build_type: DEBUG
cocos2d.x.build_time: 01:23:16 Jun 11 2016
cocos2d.x.compiled_with_gl_state_cache: true
gl.supports_ETC1: false
gl.supports_BGRA8888: false
gl.max_texture_size: 4096
gl.supports_PVRTC: true
gl.renderer: Apple Software Renderer
gl.vendor: Apple Inc.
gl.max_texture_units: 8
gl.max_samples_allowed: 4
gl.supports_OES_packed_depth_stencil: true
gl.supports_NPOT: true
gl.supports_discard_framebuffer: true
gl.supports_OES_depth24: true
}

cocos2d: fullPathForFilename: No file found at script/jsb_prepare.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
2016-06-11 01:24:29.946 tutorial-hot-update-mobile[5988:320833] cocos2d: surface size: 1704x960
Success to load scene: db://assets/scenes/menu.fire
这个错误不影响更新下载。

感谢cocos技术团队的支持,终于进了一步,可以调试热更新了,我的cocos creator版门1.1.1beta,21点程序更新的github上最新的,mac。但是非调试模式还是无法load下载下来的场景。模拟器方式更新下载场景后还是报错,重新打开后还是无法load场景。希望技术人员有时间可以解答下:)

通过android studio打开build的安卓工程,运行时报错couldn’t find “libcocos2djs.so”,具体错误如下:

06-11 17:35:06.068 1551-1551/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: org.cocos2d.tutorialhotupdate, PID: 1551
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/org.cocos2d.tutorialhotupdate-2/base.apk”],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “libcocos2djs.so”
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:988)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:235)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:249)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

找不到so包,这个需要什么配置么?还是手动导入?
看到一个帖子http://forum.cocos.com/t/ccc-1-1-android/37200/2也是这个错误,官方每次更新版本没有跑一遍测试用例就直接让用户来做黑盒测试么???!!!

分享一下 我们在iOS装置上测试时遇到的问题:

参考这一篇 iOS 8 之后的动态沙盒路径

iOS 8 以后,jsb.fileUtils.getWritablePath() 这个方法在 app 每次执行后,取到的绝对路径都不一样

所以把绝对路径存到 localStotage 会有问题,因为下次app 执行时路径是不同的。

虽然绝对路径会一直变,可是之前写入的档案都还是存在,位于新的绝对路径中

所以我把 packages/hot-update/main.js 修改如下:

if (cc.sys.isNative) {
var storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ‘/’) + ‘your-name’);
var searchPaths = [storagePath, ‘res/raw-assets/’, ‘’];
jsb.fileUtils.setSearchPaths(searchPaths);
}

也就是每次都要呼叫 jsb.fileUtils.getWritablePath() 取得新的绝对路径,才会正确找到下载过的资源。

3赞

请问这段代码什么意思啊?是只搜索res/raw-assets/路径?src路径呢?

‘res/raw-assets/’ 和 ‘’ 这两个路径其实是我在xcode上侦错的时候,观察到原本就有的路径,我只是照填上去(也许有更好的作法)。

我这边主要是要说,因为 iOS 8 动态沙盒的关系,所以把这一次的 getWritablePath 存在 localStorage,下次启动直接拿来用一定会找不到路径

在 iOS 环境下每次启动都呼叫 jsb.fileUtils.getWritablePath() ,再 set 给 cocos 引擎才会正确

嗯,iOS 9经测试没有你说的问题

发现一个问题,当用来更新的远程服务器没有开启时会卡在检查更新状态好长时间,系统log输出AssetManager:load project.manifest.tmp失败skip hot update(非HotUpdate.js里输出的),但并没有及时把消息通知到HotUpdate.js里,导致程序要等待好久才能在HotUpdate里收到更新失败的消息。

有印出jsb.fileUtils.getWritablePath() 的值吗? 我这边测试每次都不一样的 (iPod 5, Xcode 8, iOS 8)
如果你直接拿旧的路径去用, 应该会发现怎么更新都还是旧资源。

markkkkk

求问服务器上应该放置哪些文件,是https://github.com/cocos-creator/tutorial-hot-update中的所有文件吗

哪些文件需要被访问就放哪些啊