Android compilation not working for JS - command line

I tried using the command line cocos tool to compile my JS app for android, but after it compiles and downloads it to my phone, my app doesn’t actually work.

I ran cocos run -p android and after compiling for a while, it uploaded an app to my phone with the same name as my project, but all I get is a black screen with the gl verts count and other debug info in the bottom left.

My js app runs fine when I do cocos run -p web so does anyone know what I’m doing wrong?

this usually happens when there is error in the js.
Is there any errors in the console in web?
If there is not, it could that the error happens only in the android version. What I do is use the cocos code ide to compile with a prebuilt apk and the console of the ides shows the errors but I dont know how to do it with the console and the ide is out of the web.
Maybe if you look at the logs of adb or something like that.

The only error is “Failed to load resource: the server responded with a status of 404 (File not found)” that happens once at the beginning, but it doesn’t affect the game in any way and it still runs.

Yeah, I was looking for the cocos code ide, but I couldn’t find it.

I tried using adb logcat to see all the messages, but I just get so many messages that it’s hard to parse through them.
Does anyone know how to find the package name of my application so I can filter through the log messages?

Ok, so I went through the debug output and actually found some javascript errors in my syntax that were causing the app to fail. I fixed those, and now my app actually gets farther in the process.
You can see in the picture that the GL verts thing has been replaced by the usual things that appear while the game is running.

The app now starts my main app.js file, but there is an error I’m unsure about why it’s wrong.

"Line 33863: D/cocos2d-x debug info( 9450): JS: assets/src/app.js:15:TypeError: cc.Sprite.create is not a constructor"

But that line is sprite = new cc.Sprite.create(res.british_gif);

But isn’t that the proper way of creating a sprite?

EDIT:
Realized that I’m supposed to just use sprite = cc.Sprite.create(res.british_gif); without the new
But I have another question now. Why does the console when I run the app in chrome and firefox not catch those same errors? My entire game runs just fine even though I had those errors.

Another error that I found when I ran the android version was that I typed sayAlreadyPressed() {
instead of sayAlreadyPressed: function() { in one of my layer classes.

But those errors still compiled and worked as expected as well.

I do not know why but the web version is quite less strict that the android version.

Anyway the new way to create a sprite is sprite = new cc.Sprite(res.british_gif); the create way is deprecated although it works. I do not know if they do the same but I guess so.

Could you share how did you find the js errors through console? I would prefer to use terminal myself.

Just curious, does it say that in the documentation? I didn’t see that.

Do you mean how I found the js errors through the browser console? I just see them in the console.

But if you mean how I found the js errors for the android version, I used adb debug in the terminal and then piped the debug output to a text file and then opened in Notepad++ and then used the search function to search for output related to my program.

No, I meant in android adb. Thank you for the info.

http://cocos2d-x.org/docs/manual/framework/html5/v3/inheritance/en

This is what you ask?

1 Like