Help us with Android project setup

Help us with Android project setup
0

#1

Hi All,

It seems to me that our Android tool chain might be suffering and therefor not easy for users.

  1. I know that as of some SDK release the command-line app android no longer exists. This makes part of our install instructions wrong and also means you can’t run cocos compile -p android, IIRC.

  2. Android Studio seems to be the new tool pushed for Android development, but I am not very familiar with it. Some recent topics help layout how to get started.

Can anyone afford the time to write something up about what works, what doesn’t and what the fixes need to be? Perhaps we can use this as a way to guide what we need to fix but also I can update our Android docs so new users are not suffering so much.

Edit: what I mean is write up your thoughts on what works and what issues you run into.


#2

#4

I can say that I faced absolutely no issues in setting up Android Studio. It went as smooth as: Create new project using command line, Open in Android Studio, Press run.

Cocos2dx added full C++ editing support for Android Studio in 3.15. I recently moved one of our projects from 3.13.1 to 3.16. I had to manually make changes only because I was moving an exisiting project to a newer version of cocos2dx. There is no need to use the cocos command to build/run anymore.


#7

Hi,

I do not use Android Studio (and do not want use Android Studio). I just need two commands: build and install.
Currently I am coping old Android SDK/tools and using below two commands:
cocos gen-libs -p android -m release --ap android-15 --app-abi armeabi-v7a:x86
cocos compile -m release -p android --android-studio --ap android-15 --app-abi armeabi-v7a:x86 --ndk-mode release

I think that for Android we should drop “cocos2d console” and just use:
gradlew build # to build
adb install “{file}” # to install

My current problems:

  1. How to setup properly Android build configuration: Android COMPILE_SDK_VERSION, MIN_SDK_VERSION, TARGET_SDK_VERSION
  2. How to build once cocos2d-x with gradle and use it in all my games (currently I achieved this with “cocos gen-libs” )
  3. Synchronization of Android/iOS/Win (makefile/project/solutions) projects. I think that we should go with CMake. There are some activities: https://github.com/cocos2d/cocos2d-x/pull/18154

Regards,
Chp


#8

So how do you update the android-ndk and android-sdk? Are you utilizing brew or something similar?

Right now it seems we have users that only use the command-line and others that only use Studio. Some use pre-builts and some use source. I want to make sure we document everything the best we can.


#9
  1. android-ndk: https://developer.android.com/ndk/downloads/index.html
  2. android-sdk: https://developer.android.com/studio/command-line/sdkmanager.html
    and than:

tools/bin/sdkmanager --package_file=packages.txt

In packages.txt:

platforms;android-15
build-tools;25.0.0
extras;android;m2repository
extras;google;google_play_services
platform-tools
tools

I do not setup env variables in system. I am using bootstrap script to set/source env variables (and than call i.e build command).
In that way I can have multiple build configuration (i.e. when switching to newest android sdk/ndk, cocos version etc)


#10

I currently use android studio for development of my game.

Since Android Studio 3 is around the corner, I would wait just a little because I also suspect that they will release NDK 16, which is important because they will be recommending that all C++ Project use libc++ c++_shared or c++_static as the default toolchain for android and by NDK 18 they will completely remove it.

With that, it’s really all about the gradle script in the end and how it’s configured. I’m going to use the latest release (3.16) and write paste a completely working config here if that help. using the latest and greatest of android like

  • Targeting Andoird-26 (Oreo)
  • Using c++_static or c++_shared
  • Making use of debugger in Andorid
  • Testing on Emulatior. One issue with this on Windows and Mac is that it will try to use the native desktop version of OpenGL which can cause some problems. If you don’t have a super beefy computer, you won’t because to hit 60fps switching to the SwiftShader as well

Anything else you want to test, I have the bandwidth to help :slight_smile:


#11

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


#12

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


#14

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.


#15

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.


#16

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?


#17

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


#18

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


#19

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…


#20

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.


#21

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


#22

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.

#23

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.


#24

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