This evening, I set up a development environment. because I only have an android mobile phone and I cannot afford apple, I naturally just tried to build an android environment.
My system is win7 64-bit edition. I tried to play cocos2dx 2.2.1 a year ago, so the computer originally had a complete environment, including Visual Stdio 2010, cocos2dx 2.2.1, Cygwin, etc, to remove all installed development environments from the list, let's start from the beginning.
1. Build a Win32 Development Environment
First, download cocos2dx 3.0, official website:
Http://www.cocos2d-x.org/
Download the stable version 2.2.2 and the beta version 3.0, decisive version 3.0. Downloading has many benefits.
Okay. After the download is completed, 3.0 MB, more than MB. decompress the package. What should we do next?
Want to run it on android? Or want to see the development environment?
Let's take a look at the development environment. visual stdio is used for development in windows. I downloaded an original iso file that was directly found on Baidu's online storage. It took a long time to download, decompress, and install it, then, go to Baidu and set a serial number. vs2012 is successfully started.
Open the decompressed Cocos3.0 folder. Mine is:
D: \ cocos2d-x-3.0beta2 \ cocos2d-x-3.0beta2
It will be called cocos_home
Enter cocos_home \ build, which has a cocos2d-win32.vc2012.sln file, double-click to start vs2012, it comes in (to load for a long time like)
After entering this interface, set HelloCpp as the startup project, and then click
You can see your first cocos2dx project. Cheers!
Note: The running project is named win32. Now we can edit this project in Visual Stdio2012 and run the same method to see the result, basically, you can start development.
Cocos2dx provides many sample projects. In addition to HelloCpp, there are many other projects, such as Hello *** and Test *** in the project, which can be run, and MoonWarriors similar to lightning, diamond CrystalCraze, WatermelonWithMe, etc., all of which are fun. You can try it. I feel that these games are already doing well. In fact, you can change the texture to be able to go online. Very good.
Of course, our goal is to deploy and run on android, so the next step is to deploy the above project to android.
2. Deploy to Android
Deploying it to android is complicated, but we do not need the knowledge of android NDK in android 3.0 (at least not necessary at present ), I still remember that when I was tossing Cygwin, I was exhausted. In version 3.0, you only need a line of code to build an android project,Yes, it's just a line of code!
Refer to this post
Http://cocos2d-x.org/news/148
In fact, it is very simple. First open the command line, enter the cocos_home \ build directory, and then enter:
$ python android-build.py hellocpp
Press enter. It's easy.
Not successful? It is normal because there are still some preparations.
First, this line of code starts with python and executes the android-build.py script, so you have to have a python environment, my python runtime environment is python27, configure the environment variables.
The end of this line of code is the project name hellocpp to be deployed. The path of this project is
Cocos_home \ samples \ cpp \ hellocpp
The following folders are displayed:
Let's take a look at the following three items:
Classes contains the cpp Code.
Proj. android is the android project directory to be deployed.
Resources contains Resources shared by various platforms. However, when you build these Resources, they are automatically copied to proj. android.
Okay. Go to proj. android and find some common files in android projects, but there is basically no content. We know that the principle of deploying cocos2dx to android is to use androidNDK to build some local activities. So,
$ python android-build.py hellocpp
The premise that this line of code is successful is that you have to configure the android NDK environment. The configuration method is to download the latest android NDK development kit first. I downloaded the ndk r9c.
Https://developer.android.com/tools/sdk/ndk/index.html
After downloading, configure the environment variable and put the root directory of the ndk under the path variable. Basically, you can start the deployment. Before executing the Magic Code, check whether your configuration is complete:
Necessary configurations include
Jdk
Android sdk
Android ndk
Python
If you have developed java and android before, jdk and android sdk should have been configured, mainly by adding environment variables of ndk and python.
Everything is ready, execute that line of magic code, and access
Cocos_home \ samples \ cpp \ hellocpp \ porj. android \
Under the folder, you can see that some new files are added.
If no error is reported for the execution result, it will basically succeed. If an error is reported, the environment variable is not configured properly. For example, when I first set the environment variable, the ndk is not configured. As a result, after the build project is installed on the mobile phone, it will flash back.
The next step is to use ant to build and package the same as any well-developed android project. You can also use eclipse. I usually use eclipse to import it, the result shows that this project depends on another project.
Cocos_home \ cocos \ 2d \ platform \ android \ java
Import them together, and then clean it. No error is reported. Okay, run it on your mobile phone and you will see:
The phone is also running, And next we can start writing our first Cocos2dx project !!