Help us with Android project setup

I am happy to test any setups for android studio, I want to start developing for android and I think this can be a good chance for me to test things. I am trying to figure out which is the best setup for android anyways, so might as well share it with community from a beginners point of view.

So anyone can suggest/explain how they are developing on android, and I will try to test and see if it works, and if there are any problems. I can also point out any advantages / disadvantages from other methods

I’m surprised so far how Android Studio makes development easier.

As a new user, I struggled with android setup for over a week and I almost gave up on cocos2dx. This is what I think.

  1. I use visual studio for for developing cocos2dx c++ projects and after I have removed all the bugs, then I attempt to cross compile for android.

  2. When building for android, I use the commandline because it always works for both android and android-studio projects. I will try to write a tutorial over this weekend.

yup @slackmoehrle it is difficult to compile for android from command line and i also faced lots of troubles. Finally i justtttt create a new project from cocos command line and didn’t compile it and simply open android-studio project in my android studio IDE and compile it now its working fine for me.

I think it is good to add a note that most emulators require compilation to x86.
So if someone wants to run on an emulator, then do not forget about it.

Prerequisites must be updated too.
Add VS 2017.

Also, Visual C++ 2012 Redistributable x86 is necessary for win32 project.
The VS 2017 installer does not have this option, you must download and install it yourself.

API level 19 is required

What does this mean? min, target, compile?

Please add also to every release android settings used for testing. I still do mot know how to really properly setup it.
I just updated my apps and have 10x more crashes

I’d like to relate my experience of one year ago as a first-time cocos2d-x Android developer. I found that deciding upon and installing the right development tools was one of the most difficult tasks I had to undertake. I spent endless hours searching the mostly-outdated cocos2d-x forums, watching outdated videos linked from the cocos2d-x site, purchasing and reading the latest books from Packt Publishing (2015 being newest) which told me how to use the obsolete Eclipse plug-in. I had no success getting either Eclipse (which was really hard to find), or Android Studio device emulation to work. Slackmoehrle finally directed me to the installation docs page for the most up-to-date information. I finally settled on doing my editing in Xcode, debugging using Mac OS as the target with screen configurations that mirrored the dimensions of Android devices (which was faster to build than native Android), and final testing on different multi-OS Google Nexus phones using Terminal commands. These choices ended up being good ones for my development, and I was glad I took the time to figure it all out in advance. But it would have been nice if I could have easily found this information on how to install this set of development tools and environments when I first started.

Then I started development, porting my 16-level Apple SpriteKit game to cocos2d-x, which went fairly smoothly thanks to cocos2d-x’s good online API documentation. There were a few conversion challenges along the way, which I’ve documented here: www.doffen.org/porting-spritekit-to-cocos2d-x, if you’re curious.

Here are a few suggestions for the installation docs page at cocos2d-x.org/docs/static-pages/installation.html:

  • This page needs a paragraph at the top stating something like “This page contains links to our most up-to-date installation advice. Cocos2d-x development environments are in a constant state of flux, and information you see elsewhere is likely to be outdated.”
  • This page could also have a paragraph stating: For iOS development on a Mac you should use …, for Android development on a Mac you could use either … or …, etc.
  • I had several false starts because setup.py wasn’t documented well here. Is a trailing slash required on the ANDROID_NDK_PATH and ANDROID_SDK_ROOT? (yes it is.) Do you need to specify the bin sub-directory for your ANT_ROOT directory? (yes you do.)
  • How about some samples of the most useful Terminal commands, such as “android”, “cocos new …”, “cocos compile …”, “cocos run …”, and ‘adb logcat | grep “D/cocos”’, as well as a suggestion for adding the directory for these tools to the search path, and a suggestion on which directory to make as the current directory? This may seem like excessive hand-holding, but it can ease the pain for unfamiliar new users.
  • Why does the Mac OS installation page refer to iOS targets? Isn’t the page for Mac OS supposed to be about targeting Mac OS, and the page for iOS supposed to be about targeting iOS?
  • Be sure to mention the suggested changes to AndroidManifest.xml, strings.xml, and Android.mk, as well as where to find the directories that contain the master copies of these files.
  • Take a look at this web site for some helpful Android development advice that can and should be incorporated into your getting-started materials online: heyalda.com/13-things-every-cocos2d-x-c-android-game-developer-should-know/.

I see that today the link to the installation page is broken, which may mean someone is already in the process of improving it. I’m very glad someone is working on these important instructions for getting started with cocos2d-x development. Thanks for doing it!

Dave

1 Like

Sorry, but most of your bullet points are obsolete, because the cocos command can’t be used anymore and the preferred way is using gradle and Android Studio. But you’re right, the website doesn’t have a good documentation about who to start…

This is now fixed with a nginx re-direct to the correct location now. I apologize. I missed another one. This makes 106 rules.

I will review your feedback and make the best changes today. I appreciate you taking the time to write this for us.

If you also have feedback, please hit me up! I am far from perfect when it comes to making everyone happy.

1 Like

I realize this is all in flux, so I want to point out current problems with the Installations pages.

  • Just a suggestion: How about renaming “Installations” to “Getting Started with Installation”
  • Clicking on “Installations - Android” goes to the deprecated Android command line instructions, instead of the instructions for installing Android Studio.
  • There are no working links to download the current stable version of cocos2d-x that I could find.
  • The cocos2d-x/docs screens are not printable from any browser.

It could work

already fixed in this PR: https://github.com/cocos2d/cocos2d-x-docs/pull/65

Yeah, but they are on our downloads page. I can add some links to the sidebar.

There is no need to print. Internet printing is a nightmare, so I doubt we will work on this. We used to make a PDF and EPUB but nobody downloaded them.

But the downloads page links don’t work for me.

it will, there is a database issue, currently. There is a topic about this issue.

The database issue has been resolved.

Here’s my (so far unsuccessful) experience using the latest installation instructions while trying to install the current tools for a new C++ cocos2d-x 3.16 project using Android Studio v3.0.1. I’m using the same Mac with High Sierra that was used for making my last game, which used Terminal commands to build for Android. But since Terminal commands no longer work for building cocos2d-x for Android, I’m now switching to Android Studio.

I stumbled across several different errors trying to build and run CppTests. The instructions don’t tell you that you need to import “build.gradle” to load a project into Android Studio, but I remembered this from my previous attempts at building cocos2d-x in Android Studio in the past. (Hint: instructions for running CppTests should mention build.gradle). Anyway, after trying lots of different things and searching online for clues as to the causes of my CppTests building problems, I ultimately decided that the PATH and environment variables that I set up for my previous Terminal-based project in .bash_profile were probably interfering with the operation of Android Studio. I therefore commented out every line of .bash_profile. Then I rebooted, completely uninstalled Android Studio using instructions at howchoo.com, and installed a fresh copy. I also got a fresh copy of cocos2d-x.

So now that I had a “clean” environment to work with I proceeded to build and run CppTests using the emulator for a Nexus 6P with API 25. But it is still failing with errors that give no clear indication stating how to fix them. A popup box says: “Application Installation Failed: … Failed to Finalize Session: INSTALL_FAILED_NO MATCHING_ABIS: Failed to extract native libraries, res = -113.” And in the Messages Gradle Build window is a red-error-circle on the line that says: “Android NDK: Application targets deprecated ABI(s): armeabi”. See this screenshot.

Why does this happen with a clean build, and what do I do to fix it? And how can you improve the installation instructions so that others don’t stumble here as well? If you want to attract new users to Cocos2d-x, it is important to give clear directions on how to get started, so that they don’t get discouraged and decide to try out other multi-platform environments like Unity.

Thanks for taking a look at this!

The emulator ist not armeabi. So you need to add x86 to the target list or test on a real device.

See gradle.properties in proj.android-studio:

# List of CPU Archtexture to build that application with
# Available architextures (armeabi | armeabi-v7a | arm64-v8a | x86)
# To build for multiple architexture, use the `:` between them
# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86
PROP_APP_ABI=armeabi

the last line has to be at least

PROP_APP_ABI=armeabi-v7a:x86
1 Like

The Instructions work for me, I tested them not long ago. Let me run through them again.

Thanks for the tip, Mars3142! Now someone needs to update the the CppTests instructions to mention:

  • import the file named build.gradle
  • emulator uses x86, so update proj.android-studio/gradle.properties with the line: PROP_APP_ABI=armeabi-v7a:x86
    Then others won’t waste hours uninstalling, reinstalling, googling error messages, and generally trying to figure this out, like I have.

Can you try building a cocos new .. and tell me if it works for you would of the box?