Cocos2d-x 3.1.1 Learning log 11--A Windows Android environment build (must be useful for you!!) )

Source: Internet
Author: User

Installation steps:: (How painful the understanding!!) )1. Configuring the JDK
    • Jdk:
    • Set Environment variables:
Java_home=c:\program Files (x86) \java\jdk1.7.0_21 classpath=.; %java_home%\lib; Path increases %java_home%\bin;
After setting open cmd, enter java-version If the following prompt 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, mix Ed mode, sharing)
2. Download the android SDK

Google provides an ADT (Android Developer Tools) for Android developers, which includes the SDK and Eclipse.

3. Download Android NDK
4. Download the ant

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:
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 appears, indicating 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 "License" for more information. >>>

cocos2d-x Download and configuration1. Download Cocos2d-x
i downloaded the cocos2d-x3.1.1.
2. Setting Environment variables
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-r9d 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 effect
The 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 projects1. 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're typing 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\mbgame runing command:new> Copy template into f:\cocos2dx\mbgame\mygame1> Copying cocos2d-x files...> Rename proj ECT name from ' hellocpp ' to ' mygame1 ' > replace the project name from ' Hellocpp ' to ' mygame1 ' > replace the Project PA Ckage name from ' org.cocos2dx.hellocpp ' to ' com.colin.mbgame '

This shows that we have successfully created a project, 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]
now we are typing in cmd:
F:\cocos2dx\mbgame\mygame1>cocos compile-p android-j 4

It means that we want to compile the current directory of the Android project, and can have 4 compile tasks, so my 4-core machine is full of negative run, such as no accident, should be able to see the compilation started, 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.

In the process, ant nearly died because of:

Environment variable ant_home is also to ANT's decompression directory: ant_home:e:\ant\apache-ant-1.8.1\ bin;

I faint!!! Guess what, Ant_home's configuration, can't add semicolons; I've removed the semicolon, and I can't add bin. The Law!! Hey......


Do not know can add my QQ group: 239982941 ( cocos2d-x 3.1.1 Learning Group )

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.