Cocos2d js hello world project fails building for android

Hello All,

I have created a new cocos2d-x javascript project , when I try to run on android it gives me a weird error

Building mode: debug
Using Android Studio project : D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android
Building apk…
running: ‘“D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\gradlew.bat” --parallel --info assembleDebug -PPROP_COMPILE_SCRIPT=0 -PPROP_NDK_MODE=debug’

Initialized native services in: C:\Users\HP.gradle\native
Connected to daemon DaemonInfo{pid=14016, address=[4e835e38-cc0d-4854-af27-b87ddf8b5799 port:53946, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], state=Idle, lastBusy=1522236770029, context=DefaultDaemonContext[uid=7cf5d749-592b-4bf8-a82a-000fb68ea65a,javaHome=C:\Program Files\Java\jdk1.8.0_161,daemonRegistryDir=C:\Users\HP.gradle\daemon,pid=14016,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=IN,-Duser.language=en,-Duser.variant]}. Dispatching request Build{id=9947181e-9c8b-472d-9236-950a18bb3e1c.1, currentDir=D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android}.
Received result org.gradle.launcher.daemon.protocol.BuildStarted@69f1a286 from daemon DaemonInfo{pid=14016, address=[4e835e38-cc0d-4854-af27-b87ddf8b5799 port:53946, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], state=Idle, lastBusy=1522236770029, context=DefaultDaemonContext[uid=7cf5d749-592b-4bf8-a82a-000fb68ea65a,javaHome=C:\Program Files\Java\jdk1.8.0_161,daemonRegistryDir=C:\Users\HP.gradle\daemon,pid=14016,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=IN,-Duser.language=en,-Duser.variant]} (build should be starting).
The client will now receive all logging from the daemon (pid: 14016). The daemon log file: C:\Users\HP.gradle\daemon\3.3\daemon-14016.out.log
Starting 2nd build in daemon [uptime: 7 mins 9.162 secs, performance: 99%, no major garbage collections]
Executing build with daemon context: DefaultDaemonContext[uid=7cf5d749-592b-4bf8-a82a-000fb68ea65a,javaHome=C:\Program Files\Java\jdk1.8.0_161,daemonRegistryDir=C:\Users\HP.gradle\daemon,pid=14016,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=IN,-Duser.language=en,-Duser.variant]
Creating new cache for plugin-use-metadata, path C:\Users\HP.gradle\caches\3.3\plugin-resolution\plugin-use-metadata.bin, access org.gradle.cache.internal.DefaultCacheAccess@55d5ae1e
Creating new cache for client-status, path C:\Users\HP.gradle\caches\3.3\plugin-resolution\client-status.bin, access org.gradle.cache.internal.DefaultCacheAccess@55d5ae1e
Starting Build
Settings evaluated using settings file ‘D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\settings.gradle’.
Projects loaded. Root project using build file ‘D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\build.gradle’.
Included projects: [root project ‘proj.android’, project ‘:cocosjstest’, project ‘:libcocos2dx’]
Parallel execution is an incubating feature.
Evaluating root project ‘proj.android’ using build file ‘D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\build.gradle’.

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\build.gradle’ line: 5

  • What went wrong:
    A problem occurred evaluating root project ‘proj.android’.

Could not find method google() for arguments [] on repository container.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 1.579 secs
Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Build file ‘D:\Workspace\cocos2d\cocosjstest\frameworks\runtime-src\proj.android\build.gradle’ line: 5
A problem occurred evaluating root project ‘proj.android’.] from daemon DaemonInfo{pid=14016, address=[4e835e38-cc0d-4854-af27-b87ddf8b5799 port:53946, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], state=Idle, lastBusy=1522236770029, context=DefaultDaemonContext[uid=7cf5d749-592b-4bf8-a82a-000fb68ea65a,javaHome=C:\Program Files\Java\jdk1.8.0_161,daemonRegistryDir=C:\Users\HP.gradle\daemon,pid=14016,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=IN,-Duser.language=en,-Duser.variant]} (build should be done).
Error running command, return code: 1.

can any one say me what the error is ?

What cocos2d-x version? Using Android Studio?

I have cloned the latest code from github.
cocos2d-x-3.17
Cocos Console 2.3

From v3 or master? Are you using Android Studio?

I have run using cocos console
cocos run -p android -j 4
I am using v3 branch.

We dont support command-line builds any more as the Google removed the android command-line tool that we depended upon. Now you should use Android Studio.

1 Like

Can I find the documentation or steps to open it in android studio ?
Also I have built it with cocos2d-x cpp project , build was generating fine but crashes in android .

Just open the proj.android directory from Android Studio.

1 Like

I am glad this works now , while building from android studio and running on the device . But the readme file in git needs to be updated !
Thank you very much for your support.

ok, I will review the README and submit a PR. https://github.com/cocos2d/cocos2d-x/pull/18760

1 Like