cocoscreator2.2.2 jsb.Downloader Android平台断点续传问题

startCheck(){
//var storagePath = jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ‘/’;
var storagePath = MultiPlatform.getInstance().getDownloadPath();

    console.log('Storage path for remote asset : ' + storagePath);
    this._apkPath = storagePath+'test.apk';

    //var web = "http://download.hs323.com/app/hs_hzmj-release.apk";
    var web = "http://cdna.wolfmedia.in/RoyalTeenpatti/xx.apk";
    this.tip.string = "start download";
    this.downloader = new jsb.Downloader();
    this.downloader.setOnTaskError(function(sender,errorCode,errorCodeInternal,errStr){
        console.log("errorCode="+errorCode);
        console.log("errorCodeInternal="+errorCodeInternal);
        console.log("errStr="+errStr);
        //this.downloader = null;
    }.bind(this));
    this.downloader.setOnTaskProgress(function(sender,bytesReceived,totalBytesReceived,totalBytesExpected){
        // console.log("已下载完成大小="+bytesReceived);
        // console.log("总大小="+totalBytesReceived);
        // console.log("预期总大小="+totalBytesExpected);
        // var percent = totalBytesExpected ? totalBytesReceived * 100 / totalBytesExpected : 0;
        // console.log("percent:"+percent);
        // var lblDownload = cc.find("Canvas/lblDownload");
        // var lblscript = lblDownload.getComponent(cc.Label);
        // lblscript.string = "已经下载游戏"+ Math.floor(percent)+"%";

        console.log(`getDownloadedBytes/getTotalBytes:${bytesReceived}/${totalBytesExpected}`);
        let rate = totalBytesReceived/totalBytesExpected;
        var percent = totalBytesExpected ? (totalBytesReceived * 100 / totalBytesExpected).toFixed(1) : 0;
        this.tip.string = `update:${percent}%`;
        this.progressBar.progress = rate;
    }.bind(this));
    this.downloader.setOnFileTaskSuccess(function(sender){
        console.log("downLoad sucess!!!");
        //调用安装
        console.log("APK_Path",this._apkPath);
        MultiPlatform.getInstance().installClient(this._apkPath);
    }.bind(this));
    this._bonesTask = this.downloader.createDownloadFileTask(web,this._apkPath);
}

之前用creator2.0.8 jsb.Downloader下载apk到本地断点续传是ok的。升级到2.2.2就没有断点续传了,经常下载失败每次都要重新开始下载,这个问题只出现在安卓,windows和模拟器都可以断点续传,ios没试过。随便弄个新项目复制这段代码就能出现问题。

  • Creator 版本:

  • 目标平台:

  • 详细报错信息,包含调用堆栈:org.cocos2d.helloworld W/System.err: java.net.SocketException: Socket closed

  • 重现方式:

  • 之前哪个版本是正常的 <!creator2.0.8–>:

  • 手机型号 :

  • 手机浏览器 :

  • 编辑器操作系统 :

  • 编辑器之前是否有其它报错 :

  • 出现概率:必现

  • 额外线索:

就没有人遇到过问题吗

我遇到了怎么处理啊

碰到相同的问题了,最后改为了安卓那边自己实现,用的是filedownloader,可以自己git上搜下具体的用法。

这个问题不止一个人说过,官方根本就不带搭理你的 估计他们自己默认这个问题了吧 或者说按它们目前的程度 没法解决,你就凑活着用吧

我用2.2.2的时候断点续传没有问题啊? 一切都很正常。
new的downloader下载失败后,再用这个downloader去createDownloadFileTask就可以了啊

以前我遇到过这个问题,后来发现问题不是出在客户端代码逻辑,而是网络运营商!后来我们换了一家运营商就好了

是这样,你作为引擎 不应该有个细微问题就断掉,而且我测试的时候 很明显 网络是通的 返回的错误堆栈 是明显JAVA端库的错误 但你加个重连就是了 JAVA网络库很不稳定 ,不要出个错误然后把问题甩给用户,你内部就应该有个超时重连的机制 你应该把能包容的问题都包容掉 除非真的断网了 你才应该把问题 反应到用户端, 显然 引擎没有做到这种容错性,说它有问题 一点都不夸张

:rofl:讲句公道话,虽然cocos官方的确会漏掉一些问题不处理,但是你一直抱怨老版本里的bug还怨官方不负责是不是有点强人所男

是因为服务器相关设置的问题

退一万步说,就算cocos有个超级大BUG整好被你碰到了,他们需要一个月来修,你是等一个月还是自己想办法处理? 所以啊,抱怨是没有意义的,想办法解决才是正确的选择。每次遇到问题都是增加你价值和阅历的机会。共勉吧,朋友。