Mac system COCOS2DX + Android Development environment configuration

Source: Internet
Author: User

Mac system COCOS2DX + Android Development environment configuration

/******************************************************

This article is mainly reproduced from: Http://www.cnblogs.com/wt616/p/3758828.html (the eldest brother is really very cow, thank you!) )

Then, the article added some of their own understanding and the actual operation of the problem encountered in the solution. And these are the ways of greatness.

Netizens, but because of more search, many of the source address are not recorded well, sorry, if you see, tell me, I add the address.

******************************************************/

Environmental Building Steps

    1. The required software and

(1) Mac system, my version: OSX Yosemite10.10

(2) Cocos2dx, my version: cocos2d-x-2.2.5

: Http://www.cocos2d-x.org/download

(3) Eclipse for Mac, Android SDK (ADT)

These two use the latest version, and Google has packaged the two together, greatly reducing the work of the Eclipse+android development environment, referred to as the Eclipse ADT bundle, including the development needs of the software or SDK, not recommended to download separately, Download adt,:http://developer.android.com/sdk/index.html directly and remember to choose Mac version, 32-bit or 64-bit.

My version: adt-bundle-mac-x86_64-20140702

(4) NDK

The NDK is a tool for developing Android programs in C + +.

: Http://developer.android.com/tools/sdk/ndk/index.html, remember to choose Mac version, 32-bit or 64-bit.

My version: android-ndk-r10c

(5) Jdk,jre

According to the netizen, do not download, when first run eclipse, will prompt no JDK, then can download automatically. But I downloaded it by myself.

My version: JRE-8U25-MACOSX-X64.DMG,JDK-8U25-MACOSX-X64.DMG

Http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

Http://www.oracle.com/technetwork/java/javase/downloads/index.html

After the installation is complete, run Eclipse, ready to try, but eclipse can not open, the hint needs JavaSE6, then the question came, according to the Netizen introduced, Mac system from 10.10 has not supported JAVASDK1 to 7, only use the latest version of Java, then how to solve the problem of no JavaSE6 can not open eclipse?

The solution is as follows:

1) Enter directory (Java actual installation directory): Macintosh hd/library/java/javavirtualmachines/jdk1.8.0_25.jdk/contents/

2) Modify the Info.plist file

Put

<key>JVMCapabilities</key>

<array>

<string>CommandLine</string>

</array>

Revision changed to

<key>JVMCapabilities</key>

<array>

<string>JNI</string>

<string>BundledApp</string>

<string>WebStart</string>

<string>Applets</string>

<string>CommandLine</string>

</array>

Of course, the Info.plist file does not have permission to modify

You need to sudo a bit and then use the chmod a+w command to modify the file to be writable, using Nano or vim to modify the file.

(6) Recommendations

It is recommended to extract the above into the same working directory, such as decompression in the Projects directory, projects/cocos2d-x-2.2.5,projects/adt-bundle-mac-x86_64-20140702,projects/ Android-ndk-r10c.

2. New COCOS2DX Project

(1) Open terminal

(2) Enter the Project-creator directory

CD ***/projects/cocos2d-x-2.2.5/tools/project-creator

(3) Execute create_project.py script, generate COCOS2DX each version of the project file

./create_project.py-project Myprojectname-package Com.packagename.myprojectname-language CPP

Format Description:

MyProjectName, project name, self-setting

Com.packagename.myprojectname, the name of the package, set itself

(4) After executing the script, the resulting project file is placed in the Projects/cocos2d-x-2.25/projects directory.

Where Proj.ios is the directory where the iOS project files reside.

Proj.android is the directory where Android-related files reside.

(5) Recommendations

Before each Android transplant, it's a good idea to compile and run under iOS without problems before doing Android-related operations.

3. Configuration of Android-related environment variables

(1) Open terminal, Input pico. Bash_profile, enter

(2) Enter the following configuration:

Export android_sdk_root= ***/projects/sdk/

Export android_ndk_root=***/projects/android-ndk-r9d/

Export COCOS2DX_ROOT=***/PROJECTS/COCOS2D-X-2.2.3/

Export ndk_root=***/projects/android-ndk-r9d/

Export path= $PATH: $ANDROID _sdk_root

Export path= $PATH: $ANDROID _ndk_root

WHERE, * * * is a full path, such as/users/yourname/documents

"=/" do not have spaces, otherwise the configuration is invalid.

After the input is complete, Control + x is saved, then Y, enter, done.

(3) test configuration is successful

Close the terminal, and then reopen the terminal.

If there is a problem with the configuration, the terminal will prompt:-bash:exoort:command not found

If there is no hint, the configuration is successful.

4. Create a first Android project

(1) Start Project Eclipse,new, select Android Project from Existing Code,browse to proj.android in the COCOS2DX project directory you just created, remember to cancel copy Projects to workspace, otherwise the compilation has a problem; then finish is created.

(2) When the project is first imported, the entry activity is automatically generated and inherits from Cocos2dxactivity. For the first time, you need to import manually by creating a new project, selecting Android Project from Existing Code,browse to ***/projects/cocos2d-x-2.2.5/cocos2dx/ Platform/android folder.

(3) Before compiling, you need to add ndk_root:ndk_root= "***/projects/android-ndk-r10c" under the # options in build_native.sh.

(4) Compile error problem:

1) ' Transform ' is not a member of ' STD ' ERROR problem, workaround, add header file in LabelReader.cpp: #include <algorithm>.

2) do not find the head file problem:

# include "AppDelegate.h"

#include <jni.h>

#include <android/log.h>

Solution: Search users encountered problems and solutions, check the under the project under the properties->c/c++ general paths and symbols in the various path configuration is not a problem. And my problem is: just open eclipse run no problem, just open once main.cpp, will error, restart eclipse There is no problem, do not open main.cpp there is no problem. For the time being, it is late at night, another day to check this problem, if the Netizen God knows what is the problem, hope to exchange AH.

(1) Compile, build. So library

Open terminal, execute script ***/proj.android/build_native.sh

If you compile an error, you will be prompted and then modified as prompted.

Compile successfully, it will appear:

[Armeabi] Install:libcocos2dcpp.so = libs/armeabi/libcocos2dcpp.so

(2) Run, generate APK

In Eclipse, click Run to generate the APK file directly.

Note: After each compilation build_native.h is successful, right-click on the project file in Eclipse, then refresh the project by clicking Refresh, replace the original. So file in Eclipse, and then package to build the APK.

(3) Installation and commissioning procedures

If you have already configured your Android virtual machine, you can select it at runtime and see the program effect directly on the virtual machine.

To install a program on a real machine, there are two methods:

1) Put the generated apk file, in the Proj.android/bin directory, through Android management software or other methods, put the APK on the phone, and then manually install, run.

2) mobile phone to open the developer mode, via USB to connect the phone to the computer, turn on the phone's USB debugging, Eclipse recognized the phone, click to run, you can directly install the APK to the phone. Remember to operate the phone without a lock screen. This method only applies to some mobile phones, some phones must be manually installed APK.

Mac system COCOS2DX + Android Development environment configuration

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.