[resolved] ability to hide the js file in the android apk?

[resolved] ability to hide the js file in the android apk?
0.0 0


For anybody who would like to hide the js file but has no idea like me.
There are 2 options under tools section

  1. closure-compiler (doesn’t work for me)
  2. cocos2d-compiler

i use option 2 and that finally work for me.
i have to say it is a painful process to learn how to do it for me.
here are the steps.

copy compiler_config_sample.json from tools/cocos2d-console/console/bin/
edit and list all your js in the list. (this help you compress all js file into 1 jsc files)
tools/cocos2d-console/console/cocos2d.py jscompile
to convert all your js file to jsc file
there are 2 options here, it can pack all your js file to jsc file, 10 in 10 out.
or it can pack all js file into 1 single file (doesn’t work for me for unknown reason)

if the above doesn’t work for you ,here is one extra steps nobody ever mentioned before (at least i can’t dig anything up in this forum)
in theory this step can be ignore but it just work for me.

  • modify the AppDelegate.cpp ScriptingCore::getInstance()->runScript(“cocos2d-jsb.js”); to ScriptingCore::getInstance()->runScript(“cocos2d-jsb.jsc”);

  • copy scripting/javascript/bindings/js/ folder and paste in your projects/src folder (so they can be convert to jsc as well)

  • modify js/jsb.js and change all require from js to jsc

  • modify your main js (cocos2d-jsb.js or main.js) and change require jsb.js to jsb.jsc and all your file extension from js to jsc

  • run jscompile again to convert all js file to jsc file.

  • in your proj.android/assets/ folder delete all jsb_xxx.js and move all your usb_xxx.jsc from proj.android/assets/js to proj.android/assets/

cocos 2d 2.2.x

original message above
Hi All,

First of all i am not 100% sure i should post this here, but since i am using jsb, i put the post here.
Recently i start testing pack my html5 code to android apk using jsb.
the result is all good so far, the apk create successfully and it can install and run on a real device for testing.

as a pkg file, i can simply unpack the whole thing by winrar.
and i can see all the asset file in the asset folder and ALL THE JS CODE!
are there anyway to hide those js code?

i think it is way too easy for someone to clone the whole game code without any technical skill.

thanks for any input in advance.


Hi, @zax,

You can use Closure Compiler to compress and obfuscate your code into one js file that is unreadable.
Closure Compiler is already included in our html5 engine, but you still need to install JRE 1.7 and ant, then in project root, you can do: ant compile_test_advanced. The build file is build.xml



Hi Huabin,

i’ve ran the obfuscate.py under tools following this instructions

it gave me the obfuscate.xml and then i ran ant -buildfile obfuscate.xml and it generate the game.js
all looking good so far but what else do i need to do?

i’ve tried update AppDelegate.cpp’s ScriptingCore::getInstance()->runScript(“cocos2d-jsb.js”); to ScriptingCore::getInstance()->runScript(“game.js”);
but rebuild the pkg and it runs with black screen.
the above links just teach how to adjust it under Xcode and i can’t find any android instructions.
Can you please advice me what else need to be done so it will work?