Closed zj8487 closed 8 years ago
just not work on the real android device! so first package an app and install and adb log
require used in main.js is in closure, it will not be confused with cocos2d-js require
but it woks cocos2d-js 3.5~~~~`
how can i do to make it work?
i will try to make all require in closure today. and feedback
this is my app.js for bearcat. and all the other dependency is migrate to requireUtil.js
, but it still not woks.
require('./bearcat-bootstrap.js');
require('pomelo-cocos2d-js');
var Promise = require('promise');
var bearcat = require('bearcat');
window.bearcat = bearcat;
window.Promise = Promise;
cc.game.onStart = function() {
cc.view.adjustViewPort(true);
cc.view.setDesignResolutionSize(960, 640, cc.ResolutionPolicy.EXACT_FIT);
cc.view.resizeWithBrowserSize(true);
cc.director.setProjection(cc.Director.PROJECTION_2D);
cc.loader.resPath = "res/images/";
cc.loader.audioPath = "res/audio/";
var self = this;
bearcat.createApp();
require('./src/util/requireUtil');
if (cc.sys.isNative != true) {
bearcat.use(Object.keys(__bearcatData__.idPaths));
}
bearcat.start(function() {
// deleted for private
}, self);
});
};
cc.game.run();
ok i will test on cocos2d-js 3.6.x version
it works on adb debug model but not work when you install the package on device!
ping
这个问题是因为 cocos2d-js 在 android 打包的 spidermonkey 有bug
主要出现在 require('xxx') 时,这个如果不存在应该丢出异常,但是有bug的话,就只返回那句
在browserify里面,需要用到require,可以进行hack处理
fileStr = fileStr.replace(/typeof\s*require==\"function\"\&\&require/g, "function(str) {throw new Error('can not require ' + str)}");
把打包出来的browserify文件,替换一下里面的require就行了
这都被你查到,厉害!
我也找了一天才发现,它在windows下面也有这个bug的,不过3.6.1版本的貌似修复了
it says there is error in main.js which is generator by bearcat grunt!
error output:
the output above is from follow: