[Reprint]cocos2d-x 3.0RC Development Guide: Android Environment built under windows

Source: Internet
Author: User
Tags windows x86

In the original, see: http://blog.csdn.net/linzhengqun/article/details/21663341

Bright red Font Please note: The text of the red font is the main Bo in the sun under the dandelion added. Red font part of the problem caused by the blogger is not responsible for any. The responsibility for other fonts rests with the original author. (This article blogger is not particularly moral integrity ....) O (∩_∩) o hahaha ~)

Installation Tools 1. Configuring the JDK
    • JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html
my system is Win7 64-bit version, but the installation is Jdk7,windows X86 version. Suppose the installation directory is in: C:\Program Files (x86) \java\jdk1.7.0_21; Of course it could be somewhere else.
    • Set Environment variables:
Java_home=c:\program Files (x86) \java\jdk1.7.0_21 classpath=.; %java_home%\lib; Path adds %java_home%\bin; This article assumes you know how to set the environment variables, if you do not know, please use search engine to find relevant data, set up after the cmd, enter java-version If the following prompt appears, Indicates that the environment variable is set successfully: c:\users\arlin>java-version java Version "1.7.0_21" java (TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot (TM) Client VM (build 23.21-b01, mixed mode, sharing)
2. Download the Android SDK
Google provides an ADT (Android Developer Tools) for Android developers, which includes the SDK and Eclipse.
Yes: http://developer.android.com/sdk/index.html can choose 32-bit or 64-bit version, I choose the 32-bit version, unzip it to a directory, I am here: d:\ Adt-bundle-windows-x86\, the directory structure is as follows: --<adt-bundle-windows-x86> --<eclipse> --<sdk> --sdk Manager.exe
3. Download Android NDK
Yes: http://developer.android.com/tools/sdk/ndk/index.html also have 32-bit and 64-bit version optional, I chose the 32-bit version, unzip it into the ADT directory, Now the directory structure of ADT is as follows: --<adt-bundle-windows-x86> --<eclipse> --<sdk> -- < android-ndk-r8e> --sdk Manager.exe
4. Download the Ant
ant is used to automatically build Android programs. Yes: http://ant.apache.org/bindownload.cgi I chose: apache-ant-1.9.3-bin.zip, also extracted into the ADT directory, Now the directory structure of ADT is as follows: --<adt-bundle-windows-x86> --<eclipse> --<sdk> --< android-ndk-r8e> --<apache-ant-1.9.3> --sdk Manager.exe
5. Download Python
    • Originally cocos2dx in different platforms must use different scripts to create and build projects, after 3.0 are unified with Python, so Windows needs to install the Python environment:
: Https://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
originally downloaded the latest version, the use of setup.py when there are syntax errors, so it is best to use the 2.7.3 version, pro-tested no problem
    • Configure environment variables: The latest version can be automatically added to the PATH environment variable, but 2.7.3 not, so we can only set it ourselves, assuming that my Python installed in: d:\Python27\
Add this path to the PATH environment variable, and when we enter Python under CMD, the following word shows that the environment variable is set correctly: c:\users\arlin>python python 2.7.3 ( Default, APR, 23:31:26) [MSC v.1500 + bit (Intel)] on Win32 Type "Help", "copyright", "credits" or "Licen Se "For more information. >>>
Cocos2d-x Download and Configuration 1. Download Cocos2d-x
currently the latest version is 3.0RC, yes: http://cocostudio.download.appget.cn/Cocos2D-X/3.0RC0/cocos2d-x-3.0rc0.zip Download the unzip to a place I am here: f:\cocos2dx\cocos2d-x-3.0rc0\
2. Setting Environment variables
CC requires the following environment variables for subsequent new projects, construction projects, etc.:
    • Cocos_console_root:cocos console path, console for new, build, release works.
    • NDK_ROOT:NDK root directory
    • ANDROID_SDK_ROOT:SDK root directory
    • Ant_root:ant root directory
These environment variables are configured by setup.py in the Cocos2d-x root directory, we start cmd, run setup.py: f:\cocos2dx\cocos2d-x-3.0rc0>setup.py  At this point the script needs us to provide the path of the ndk,sdk,ant, which we have entered according to the previous path, the entire command process is as follows: Setting up Cocos2d-x ...   -- Adding cocos2d_console_root environment variable ... OK - added:cocos_console_root = f:\cocos2dx\cocos2d-x-3.0rc0\tools/cocos2d-cons Ole/bin   - looking for ndk_root envrironment variable ... Not FOUND Please enter their path (or press ENTER to skip): d:\adt-bundle-windows-x8 6\android-ndk-r8e ADDED --added:ndk_root = d:\adt-bundle-windows-x86\android-ndk-r8e   - looking for android_sdk_root envrironment variable ... Not FOUND Please enter their path (or press ENTER to skip): D:\adt-bundle-windows-x8 6\SDK ADDED - added:android_sdk_root = D:\adt-bundle-windows-x86\sdk   - looking for ant_root envrironment variable ... Not FOUND Please enter their path (or press ENTER to skip): d:\adt-bundle-windows-x8 6\apache-ant-1.9.3\bin ADDED - added:ant_root = D:\adt-bundle-windows-x86\apache-ant-1.9.3\bin   Set up successfull: Cocos_console_root was added to registry Ndk_root was added to registry Android_sdk_root was added to registry Ant_root was added to registry   Restart the terminal or restart computer to make added system variables T ake effectThe command finally prompts us to restart the terminal or restart the system for these environment variables to take effect, generally we close the CMD and resource browser on the line, if you encounter an environment variable can not find the error, directly restart the system to try it. To test that the environment variable is in effect, reopen cmd, and enter the following command to see what should normally be the case: F:\cocos2dx\cocos2d-x-3.0rc0>set Ndk_root ndk_root=d:\adt-bundle-windows-x86\android-ndk-r8e   F:\cocos2dx\cocos2d-x-3.0rc0>set Ant_root Ant_root=d:\adt-bundle-windows-x86\apache-ant-1.9.3\bin   F:\cocos2dx\cocos2d-x-3.0rc0>set Android_sdk_root ANDROID_SDK_ROOT=D:\ADT-BUNDLE-WINDOWS-X86\SDK   F:\cocos2dx\cocos2d-x-3.0rc0>set Cocos_console_root Cocos_console_root=f:\cocos2dx\cocos2d-x-3.0rc0\tools/cocos2d-console/bin
New and built projects 1. New Project
We will use the Tools\cocos2d-console tool to create a new project, which provides the following features:
    • New to create a project
    • Compile compiles the current project, generates binary files, and the individual feels that writing as build is more appropriate.
    • Deploy the release program to a platform
    • Run compiles and publishes, and runs the program
Now we only use new, let's see what new parameters are available, hit cmd, enter: Cocos New--helpGet the following help: Usage:cocos New [-h] [-P package_name]-l {CPP,LUA,JS} [-D DIRECTORY] [-t template_name] [--no-native] [PROJECT_NAME]   Create a new project   Necessary Parameters: PROJECT_NAME project name   Optional Parameters: -H,--help display Help information -P package_name,--package package_name Set the package name, such as Com.colin.mbgame -L {cpp,lua,js},--language {cpp,lua,js} The primary language that can be used is: [CPP | lua | js] -D directory,--directory directory directory where the project is located -T Template_name,--template template_name name of the project template to create   LUA/JS Engineering Parameters: --no-native no native support.
now we enter in CMD:
f:\cocos2dx>cocos New mygame1-p com.colin.mbgame-l cpp-d f:\cocos2dx\mbgame get the following output:f:\cocos2dx> Python f:\cocos2dx\cocos2d-x-3.0rc0\tools\cocos2d-console\bin\/cocos.py new mygame1-p com.colin.mbgame-l cpp-d f:\ cocos2dx\mbgameruning command:new> Copy template into f:\cocos2dx\mbgame\mygame1> Copying cocos2d-x files...> Rename project name from ' Hellocpp ' to ' mygame1 ' > replace the project name from ' Hellocpp ' to ' mygame1 ' > replace the Project package name from ' Org.cocos2dx.hellocpp ' to ' com.colin.mbgame '
This shows that we have successfully created a project, to f:\cocos2dx\mbgame\ Look, the project directory structure is as follows: --<mygame1> --<classes> --<cocos2d> --<proj.android> --<proj.ios_mac> --< proj.linux> --<proj.win32> --<resources> --. Cocos-project.json --cmakelists.txt Can see a variety of platforms under the project has been created, while it cocos2d the entire framework is copied over, this is
good or bad opinion,
2. Build Android Project
At the same time is used to cocos2d-console, here to use is compile this command, in the cmd input below to see the help: f:\cocos2dx\mbgame\mygame1>Cocos Compile--help   Usage:cocos Compile [-h] [-s src_dir] [-Q] [-P PLATFORM] [-M MODE] [-j JOBS] [--ap android_platform] [--source-map]   compile the current project into binary   Optional Parameters: -H,--help display Help information -S Src_dir,--src src_dir the engineering root directory, such as the above should be f:\cocos2dx\mbgame\mygame1 if not set, the current directory (the directory to which CMD is located) -Q,--quiet less output -P PLATFORM,--platform PLATFORM Select a platform android|ios|mac|web|win32|linux - m mode,--mode mode debug|release, default to Debug. -j jobs,--jobs jobs Half-line compilation, if you have 4 cores, can be set to 4.   Android Options: --ap Android_platform Specify the SDK version? Have not tried, dare not to the conclusion, keep English: parameter for android-update. Without the parameter,the script just build dynamic library for project. Valid Android-platform are:[10|11|12|13|14|15|16|17|18|19]   Web Options: --source-map Enable Source-map
now we are typing in cmd:
f:\cocos2dx\mbgame\mygame1>cocos compile-p android-j 4 means that we are going to compile the Android project in the current directory, and can have 4 compilation tasks, So my 4-core machine is full of negative run, if no accident, should be able to see the start of the compilation, and finally if you see the following sentence, the compilation is successful:
BUILD Successful
Total Time:7 seconds
Move apk to F:\cocos2dx\mbgame\mygame1\bin\debug\android
Build succeeded.
we go to f:\cocos2dx\mbgame\mygame1\proj.android\bin\and we can see MYGAME1-DEBUG.APK, which shows the build is complete.
I put it on the phone to try to run, found that it seems to start the speed is a lot faster, do not know whether the psychological effect.
Run the program under Eclipse Do you remember that we have eclipse in ADT, and now we're going to import the project into Eclipse and run to see
    • Hit d:\adt-bundle-windows-x86\eclipse to eclipse.exe .
The
first time you'll be prompted to set up a workspace, you can set where the workspace is placed, and I'll default for the demo here.
    • Next we'll see if the path to the SDK and NDK is correct:
      • Select the windwos/preferences menu item to open the Options dialog box.
      • Select Android node to see if the SDK location is correct, I'm here for F:\software\adt-bundle-windows-x86-20131030\sdk , the instructions are correct, and if there is no value, manually set the SDK root directory in.
      • Then select the android/ndk node and enter the d:\adt-bundle-windows-x86\android-ndk-r8e at the NDK location
  • Next we will import the project, select File/import, Open the Import dialog box:
    • Choose android/existing Android Code into Workspace, and then next.
    • The first step is to libcocos2dx in:
      • Enter F:\cocos2dx\mbgame\mygame1\cocos2d\cocos\2d\platform\android\java in Root Directory
      • (PS: Non-reprint content: There is a problem here, so the step is to choose: general/exiting Projects into Workspace then next.
      • The goal of the first step is to import libcocos2dx, keep in mind, so the path to root directory is F:\cocos2dx\mbgame\mygame1\cocos2d\cocos\2d\platform\android )
      • At this point the libcocos2dx project is listed, click Finish to bring in the project.
    • The second step is to import our project:
      • Enter F:\cocos2dx\mbgame\mygame1\proj.androidin Root Directory .
      • The mygame1 project is listed at this time, click Finish to guide the project in.
    • (PS: Eclipse imports LIBCOCOS2DX and its own project Mbgame at this point.) You need to introduce a library LIBCOCOS2DX in Mbgame projects.
    • The steps are: Right-click the library under Mbgame->properties->android. Then add on LIBCOCOS2DX can)
    • Finally connect the phone, choose Run or debug can run the program.
    • When importing the project to eclipse, there are several pits, which are written down here, lest the people behind continue to tread on these pits:
      • No guide libcocos2dx, only the mygame1 will not compile errors, but run up will ClassNotFound abnormal, said can not find org/cocos2dx/lib/ Cocos2dxhelper class, this problem took me a long time, later in the forum to see the post only understand, hope that the following official have detailed documents.
      • Because ADT contains only the version of android4.4 (api-19) , the default is to use this version, I copied a few lower versions myself, and set the Build target to android2.3 (api-9), running the program will prompt the following error:
Unable to execute dex:java.nio.BufferOverflowException   later looked it up on the internet, sent Now it's the Android SDK build tools bug, and it's good to upgrade to 19.0.3 : Open SDK Manager and find the 19.0.3 Android SDK build tools to install.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.