Need help getting started with Cocos2d-x to build for iOS & android

I’m moving from cocos2d-iphone. Using macOS.
I downloaded http://www.cocos2d-x.org/filedown/cocos2d-x-3.13.1.zip Then I hit “Learn -> Get Started”.
I saw “Tutorials from Make School” and clicked on “Building The Game Of Lifelink and saw message: “Sorry, but the page you were trying to view does not exist.

Then, I went to “Programmers Guide” and started “iOS Setup” - nothing to see here actually as I already downloaded zip file and unpacked it into: “/Volumes/MacData/Cocos2d-x” folder .
Moving next - “Starting a new project” -> “Cocos Command-line tool”.

Now: there are many problems and confusions - in “Creating a new project” there are command for creating project using static libs, so I just tried it as I saw it there, but it’s not worked. And only after some paragraphs you showing how to compile libs, so after that I can try to create project using static libs.
But anyway - it’s not creates project using static libs even after I compiled libs because when I run “cocos new ProjectName -p projectname.com.name -l cpp -t binary” to create new project I get: “Template named ‘binary’ is not found.” And so I should google this problem and later find how to fix this - “cocos gen-templates”. But in documentation there is no info about that in step by step mode.
Only after I googled for solution, later I found this command in Unique command-line options at the end on the document, just like as additional information.
Also I got problems while adding paths while running setup.py, but I will not saying here about that… it’s enough after all. Oh dear.

And so… what to say? This documentation if really really bad. But I’m just saying. No questions about that. Maybe you will take a look…


Now, when I have finally created, build & run project for iOS. It’s simple and cool just to run in Xcode.
But I can’t find even any docs how to build for android and deploy to android store…, where is this documentation with step by step guide etc?

I have asked Make School for updated links, but no word back yet. If they don’t get back to me I will remove them.

If gen-templates has to be run before cocos new ... -t binary I am not aware. I will test this and update the doc to reflect this step.

Also, gen-templates is listed at the bottom of this doc: http://cocos2d-x.org/docs/editors_and_tools/cocosCLTool/index.html

I don’t really agree. There may be a hole in this doc about the gen-templates step, but other than that I don’t see a problem with this doc. Can you share something else specific?

In this same doc you were reading: http://cocos2d-x.org/docs/editors_and_tools/cocosCLTool/index.html is how to create, run, test, deploy, etc. The only step it doesn’t have is deploying to the app store, which it outside the scope of our docs. Once you have your .apk you need to see Google for how they want you to deploy it. Same with iOS, once you have your product they provide instructions on how to get it into the app store.

Good luck, I’ve tried a few times here and there over the past year to build/run just the basic cocos2d project for Android on OSX and I’ve never been able to do it. The only commands I’ve needed to get this done are:

cocos new -l cpp android_test

and then cd into the new project directory and execute the command:

cocos run -p android --ap android-25

It’s been a little while, but I believe android-25 is the installed SDK tools version (it could also be the build tools version, can’t remember). I can see the APK file in my bin/debug/android directory, but when the app tries to run I always fail with the runtime error:

running: '/<android sdk dir>/platform-tools/adb shell am start -n "org.cocos2dx.android_test/org.cocos2dx.cpp.AppActivity"'

Life is too short, if I need to build an android app I’ll just do it on Windows. I’ve been able to get a freshly created project up and running there. If you ever get this running please let me know how you did it.

1 Like

I am on OS X.

Are you using an emulator? Or using hardware? hardware works out of the box. This is how we work. Emulators, yeah, I have never, ever been able to get a single one working.

An emulator, I do not own an android device. I suppose it’s time to invest in one :smile:

Yes, but I wrote about that in first post. All wrong explanation in documentation.

Thats actually fun. Frankly - I already trying just to setup cocos2d-x to build a second day already. Documentation is not clear enough and just bad. How I can explain this… I don’t know it’s just bad. I’m doing step by step and it’s not working you see…

You seriously? Just from command line? But I need normal debug run and info you know… like in Xcode or something? Also I know that some signing for apk is required.
So I just have project created from command line and opened iOS target and build and so I have Xcode and I know how to develop game in it because its similar to cocos2d-iphone. But now how to develop all these for android? How just add some other res files of implement some specific sdk etc?
I developed a lot of game for App Store and no question about that, but I will use cocos2d-x just for android.

Oh yea! You fully understand me. So @slackmoehrle you see? And I think there are a toons of devs that just gave up. For example - I never used Unity and I managed to build apk in it in 15 min, so easy. But for cocos2d-x I already spent 2 days…

@slackmoehrle just create survive on your site like this - http://www.cocos2d-x.org/docs/editors_and_tools/cocosCLTool/ and then you will se how users will rate that doc as unhelpful in 99%.

Yeah, actually I am serious. I think most Android devs are using the command-line. We do support Eclipse and Android Studio and there are docs for that. I don’t think Android Studio a perfect solution yet. If I recall Google is working hard on debugging c++, etc.

I don’t see. All I see is this doc fails to explicitly state gen-templates and covering how to use emulators.

gen-templates I’ll document better.

Using an emulator I guess one should read the docs that come with these emulators. Android Studio has emulators built in but how to set them up we can’t possibly document. It isn’t Cocos2d-x specific.

That being said I have never gotten an emulator to work, so I use hardware. If I use hardware and go down through the doc you are reading I am fine (with the exception of gen-templates).

Thanks… I’ll look towards unity… will see what is worse. Damn, when I developed games for iOS only using cocos2d-iphone it was so nice so simple. Also when apportable was alive I was able just in magical and simple way port my game to android by just build and run in xcode… But as I see with cocos2d-x it’s so hard and awkward… okay\ Also it’s bad that you don’t understand how kind documentation should be… I think many people now trying using free cocos2d-x and then at starting puzzle stage - just make it work - just go away in searching some better solutions like unity… to bad.

We hear this from time to time for sure. We don’t cover in great detail the things that Apple and Google are already covering. Perhaps we could add more links to our docs to see external resources for help, but these links change and we spend time chasing down where the content moved to.

p.s. I just tried to build iOS project in Xcode, before that I just opened project and don’t tried to build it, because my main target is android. However it’s not compiling -

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_CCEAGLView", referenced from:
      objc-class-ref in RootViewController.o

iOS libs were created in debug mode.
lol… what I can say more? Ahh…
Everything I did was with problematic, almost any step. You know what all feeling in general about engine now? For sure not to use it…

I’m sorry that this is your experience. I can say honestly that an experience like this is not common for us

Are you using v3.13.1?

So you downloaded the .zip from the website?

cocos gen-templates…

cocos gen-libs…

cocos new … -t binary

Open the project in Xcode and this error occurs when compiling?

What about if you run: cocos run …

I use cocos2d-x 3.10 (mod curl), i can say the easiest way to use it:
Install cocos2dx, install cocos studio.
Set everything (NDK, SDK, whatever)
Create a project from cocos studio.
iOS run and general develop use XCode.
If you need android run, compile, use command line.
For APK Signing (and only for that) i use Android Studio.
If you need specific android debug, import project to eclipse (don’t forget to import sources, and libs, like google admob), set Android xml debug=true,
and voila, it works correctly with breakpoints, etc.

And the best tutorial:

This simple part takes for me many time and running setup.py was always unsuccessful, because even I paste folder to NDK and SDK - it’s saying that it’s wrong path same problem as here http://stackoverflow.com/questions/27773111/set-up-cocos2d-x-for-android-on-mac

I’m using latest, as described in 1st post. Thanks for this thread - Prebuilt libraries setup the definitive guide and game project kickstart for cocos2d-x 3.13.1
I can now build and run for iOS only. So one of the problems was that in cocos2d-libs project option for build active libs only in debug was set to YES, but it should be NO, so in debug all architectures will be build for iOS.
In release mode it’s set to NO and my project runs. Also other problems was there like this:

So many things to fix many hours to struggle with just installation and build.\

Now, I want to find any friendly example or tutorial: how to build, run and publish game to android. With lets say real life examples. Also I need of course to debug project as I’m doing so in Xcode for iOS, ah so amazing platform pleasure to work with. So what android gives instead?

“Now, I want to find any friendly example or tutorial”
On *nix systems is not so easy if you don’t have a little experience with paths, rights, etc.
Because every setup is individual.
But it’s not hard.

" Set everything (NDK, SDK, whatever)
This simple part takes for me many time and running setup.py was always unsuccessful"
I set up my environment with this tutorial:
http://www.cocos2d-x.org/wiki/How_to_run_cpp-tests_on_Android

For example by me the .bash_profile file looks like this (maybe there is some incorrect setting in, but it works):
# ANDROID DEVELOPMENT
export PATH="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/android-sdk-macosx/tools:$PATH"
export PATH="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/android-sdk-macosx/platform-tools:$PATH"
export PATH="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/apache-ant-1.9.4/bin:$PATH"
export PATH="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/android-ndk-r10e:$PATH"

# ANDROID DEVELOPMENT
export JAVA_HOME=$(/usr/libexec/java_home)
export NDK_ROOT="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/android-ndk-r10e"
export ANDROID_SDK_ROOT="/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/AndroidDev/android-sdk-macosx"
export ANT_ROOT="/Applications/Cocos/tools/ant/bin"

# Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
export COCOS_CONSOLE_ROOT=/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/cocos2d-x-3.10/tools/cocos2d-console/bin
export PATH=$COCOS_CONSOLE_ROOT:$PATH

# Add environment variable COCOS_TEMPLATES_ROOT for cocos2d-x
export COCOS_TEMPLATES_ROOT=/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS/cocos2d-x-3.10/templates
export PATH=$COCOS_TEMPLATES_ROOT:$PATH

# Add environment variable COCOS_FRAMEWORKS for cocos2d-x
export COCOS_FRAMEWORKS=/Applications/Cocos/Cocos2d-x
export PATH=$COCOS_FRAMEWORKS:$PATH

# Add environment variable COCOS_X_ROOT for cocos2d-x
export COCOS_X_ROOT=/Volumes/Data/Users/XXXUSERXXX/CODE-IPOD/DEV_LIBS
export PATH=$COCOS_X_ROOT:$PATH

Thanks, but mine was good too. But setup ignored my path for SDK some reason, I don’t have any clue why. TOday, after 3 days of problems I finally set up all things just to create a simple project and compile it for iOS, not sure about android yet. I just staring to do that. First will see if libs will compile and then project.

upd.: today for some reason can’t compile lib for iOS error 65. I just created project without libs…

maybe you need restart after bash_profile :smiley:

Lol nope, I restarted it many times because I already struggle with this 3 days.
So now where I can find a simple tutorial or doc that shows how on macOS build & run android project and see finally actual result, like working scene?

I found that Android Studio IDE is what I need? Any example or doc about that?

I use xcode.

Google, Cocos2d-x docs, SonarLearning, etc