Cocos2d on Android step by step

Source: Internet
Author: User

The Cocos2d was finally run on Andriod. Various pitfalls were encountered during installation. Here I will summarize these pitfalls.

According to official Cocos2dx documents, we know that the following four prerequisites are required for building an environment in Andriod:

  • Cygwin
  • Ndk
  • Cocos2dx
  • Android-sdk-tools

For the respective usage of the preceding preconditions, google. Here, we only describe the pitfalls encountered in the setup environment.

1. cygwin

Install cygwin

 Trap 1-1. Through some searches, including the Blog of Tom, it's a slow task to install it ~ It is often interrupted in half. In short, I haven't finished the next two days. I changed the image and used the ISO method. I still failed to install it.

After lz's unremitting efforts to find a domestic image ^-^, see Figure 1-1:

Figure 1-1

Everybody, give up cygwin download without installing and start the tool directly. Choose mirrors.163.com/cygwin, then install from Local Dir ~(The speed has been increased by more than 20 times ).

Open cygwin and check gcc, g ++, Pass, 1-2:

Figure 1-2

2. ndk

Android developer official website directly download ndk-r8d, version does not require r5, r6, r8 OK, cocos2d-x official website of the tutorial using r5, this article uses r8.

Unzip the ndk-r8d and set the environment variables for the ndk-r8d. You can set the parameters in either of the following ways:

  • Windows -- environment variable -- % Path %
  • Cygwin --. bash_profile, 2-1:

Figure 2-1

See Figure 2-1, pay attention to the differences between Linux and Windows paths,/cygdrive/drive letter/ndk-r8d installation path. This completes the configuration. Start cygwin and test whether the configuration is successful through Figure 2-2:

Figure 2-2

See Figure 2-2. The *. so file indicates that the command has been compiled. For the meaning of the command, this article will not be annotated. Please refer to "private house dish of a bird"...

3. cocos2dx

Download cocos2dx official website, gvim open the create-andriod.bat batch processing file, 3-1:

Figure 3-1

Cygwin, androidtools, and ndkroot are set in three environment paths. You just need to directly set the corresponding installation path. Save and execute. bat.

     Pit 3-1, sometimes. bat will not find the ndkroot path, show Couldn't find ndk, after repeated attempts to find the default path to change the ndk [android-ndk-r8d], is likely to not find the ndk, it may be a Bug. Here I use the default path to facilitate Blog writing. The fact is that the default path will not be retained after packaging in the production environment.

Specify the package name, project name,Pit 3-2. After the above settings, the execution will generate the corresponding directory structure based on the project name. If the corresponding directory in the specified folder contains files, the generation operation will certainly fail. Therefore, make sure that the specified project name is blank or you change the name of the original project.3-2, you can see that the cocos2d-x-based Andriod project structure is successfully generated:

Figure 3-2

View the directory, 3-3, and the entire project structure is generated:

 

Figure 3-3

The official statement in this path is that ndk_build build_native.sh can be compiled through cocos2dx and then the existing project will be loaded directly in the adt. The fact is that there is still a pitfall. Let's look at it.Pit 3-3, first 3-4:

Figure 3-4

  Take a look at the build_native.sh code. Pay attention to the Root path of ndk and project. The second step of path resolution may also fail. The error message returned that cygwin/gmsl wordlist failed to execute the function with the second parameter. Google clicked and did not find the solution. After thinking about the solution, manually Copy or run the batch processing in the Win environment. Pass. Finally, that is, the # build command is directly input and executed in cygwin, Pass. This replaces the ndk_build build_native.sh operation.


  
4. android-sdk-tools

Download adt-bundle from the official website of Android developer and run> New andriod project exist code> Build> gbtouch.apk. Copy the apk file to your mobile phone for installation. Cocos2dx build on anriod is complete. See Figure 4--2:

    

Figure 4-1


Figure 4-2

Pit 4-1, adb conflict problem, three reasons:

  • The local machine is connected to an external andriod device. If yes, the physical connection is interrupted.
  • The local machine is installed with 91 assistants and 360 assistants to seize the adb process. If the software is installed, shut down and restart.
  • The adb file is corrupted. Open the sdk \ tools \ adb_has_moved.txt file, which details the cause of the error and resets platform-tools \ adb.exe Based on the cause.

  

So far, Cocos2dx has been set up in the Android environment.

 

Reference http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_1_-_How_to_Create_a_New_cocos2d-x_project_on_multi-platforms

When reprinting, please indicate the source of this article: www.cnblogs.com/tmywu

Author: old fish 678

Mail: tommywu23@126.com

 

  

 

 

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.