ProgrammingGuide > Installations > Android with Terminal Installation and Setup

Android with Terminal Installation and Setup

version: Cocos2d-x v3.x
update: Updated over 2 years ago

Environment Requirements

Prerequisite

  • Download Cocos2d-x and unzip it. (maybe: ~/)

  • Download the JDK

  • Download the SDK

  • Download the NDK

  • After downloading them, unzip the SDK and NDK to the same root location.
    (maybe: ~/AndroidDev)

  • Verify that Python 2.7 is installed and is accessible.

  • Install Apache Ant and verify that it works.

  • Run setup.py to configure your Android development environment. This will
    set the necessary environment variables needed. If you haven't configured this
    environment before, you will be prompted to enter paths for variables that are
    not found.

    • Caution: You must not use the ~ sign. Use the full path to your home directory. Otherwise, the scripts will fail due to error path value.
    • *COCOS2D_CONSOLE_ROOT* environment variable to point to the bin directory under ~/cocos2d-x/tools/cocos2d-console directory.
    • *NDK_ROOT* environment variable to point to the location of where you put the NDK. (i.e android-ndk-r9d/)
    • *ANDROID_SDK_ROOT* environment variable to point to the location of where you put the adt-bundle. Example /Users/<your username>/AndroidDev/adt-bundle-mac-x86_64-20130522/sdk/. The adt-bundle-mac-x86_64-xxxx, the xxxx number maybe different. So please note this non-trival difference.
    • *ANT_ROOT* environment variable to point to the location of where you put apache-ant-x.x.x. The apache-ant-x.x.x, the x.x.x number maybe different.
  • In your cocos2d-x directory runpython setup.py

  • On unix systems, now issue the following commands:

    source ~/.bash_profile
    
  • On win32 systems, close the command line windows and restart it.

Use android-build.py to build cocos2d-x samples

  • Change your directory to the where the android-build.py script is located.
    (usually cocos2d-x/build)

  • run:

    android list targets
    

    to see what targets are available.

  • execute:

    python android-build.py -p  cpp-tests
    
  • everything should build successfully:

How to deploy it on your Android phone via command line

setuppy01.png (94.9 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

setuppy02.png (141 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

setuppy03.png (195.6 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

1.png (14.3 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

2.png (31.1 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

3.png (49.1 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

android-list-targets1.png (47.9 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

buildsuccess.png (103.5 kB) walzer@cocos2d-x.org, 2014-12-03 03:35

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.