最近cocos2d-x游戏引擎很流行 闲着没事也就了解了解
了解必须的就是开发环境了 接下来及进行配置吧 (之前android开发环境已经弄好了 如果你已经有android开发环境了直接跳过前5步骤)
一)环境配置
1. 安装jdk
2.安装eclipse (1、2步骤都会所以就不多说了)
我下载的是最新版本的eclipse jee juno 下载地址:官网 eclipse.org 进行下载 进行解压到 mac应用程序中
3.打开eclipse 安装cdt 因为最新版本的adt中有 关于ndk的引用所以你在安装adt之前必须先经过此步骤
cdt提供安装官网具体链接 http://www.eclipse.org/cdt/downloads.php
1)可以直接打开 eclipse中help》install new software》add》添加链接进行更新 链接更新地址(根据所下载的eclipse版本进行选择链接)
http://download.eclipse.org/tools/cdt/releases/juno
2)可以直接在官网链接中下载cdt文件进行安装
安装截图:
4 接下来安装adt就可以轻松通过了
1)可以在开发者官网下载地址:http://developer.android.com/sdk/index.html
2)也可直接打开 eclipse中help》install new software》add》添加链接进行更新 链接更新地址
http://developer.android.com/sdk/installing/installing-adt.html中的
http://dl-ssl.google.com/android/eclipse/
或者
https://dl-ssl.google.com/android/eclipse/
截图安装:
5.下面就是 有点耗时的工作了 下载 android sdk 和 ndk
安装好的adt截图 (在eclipse》偏好设置》或者command+, 进行显示)
1)sdk 下载链接 http://developer.android.com/sdk/index.html#ExistingIDE(选择sdk tool进行下载android各个需要的android版本)
2)ndk下载链接 http://developer.android.com/tools/sdk/ndk/index.html
3)指定 sdk路径 根据指定解压路径进行设定(注意文件目录及文件夹最好不要有空格)
4)指定 ndk路径 根据指定解压路径进行设定(注意文件目录及文件夹最好不要有空格)
6.下载cocos2d-x 下载完后解压 (下载链接:http://cn.cocos2d-x.org/download)打开终端命令行
到解压目录并执行 :
install-templates-xcode.sh -u -f
进行安装(网上查到的)安装完之后 打开 xcode 新建项目里面看到有 cocos2d-x项目模板
7.进行设置环境变量(网上查到的)vi ~/.bash_profile 回车,点击i 摁方向键最下面粘贴 ,esc键 :wq或者:wq! 进行保存退出
export ANDROID_NDK_ROOT=/Users/vic/android-ndk-r8d
export COCOS2DX_ROOT=/Users/vic/cocos2d-x
export NDK_ROOT=/Users/vic/android-ndk-r8d
export ANDROID_SDK_ROOT=/Users/vic/android/adt-bundle-mac-x86_64/sdk
export PATH=$PATH:$ANDROID_NDK_ROOT
二)创建cocos2d android项目(官网参考:http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Setting_up_Android_Development_Environment_on_Mac_OSX)
1.用命令创建android项目
./create-android-project.sh
创建日志如下:
vicmatoMacBook:cocos2d-x vic$ ./create-android-project.sh
use global definition of NDK_ROOT: /Users/vic/android-ndk-r8d
use global definition of ANDROID_SDK_ROOT: /Users/vic/android/adt-bundle-mac-x86_64/sdk
Input package path. For example: org.cocos2dx.example
com.vic.apps.test.app
Now cocos2d-x supports Android 2.2 or upper version
Available Android targets:
----------
id: 1 or "android-7"
Name: Android 2.1
Type: Platform
API level: 7
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
ABIs : armeabi
----------
。。
。。
id: 9 or "Google Inc.:Google APIs:17"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 4.2 (API level 17)
Libraries:
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, WQVGA400, WSVGA, WXGA800-7in, WXGA720, HVGA, WQVGA432, WVGA800 (default), QVGA, WXGA800
ABIs : armeabi-v7a
input target id:
9
input your project name:
androidCocos2d
Created project directory: /Users/vic/cocos2d-x/androidCocos2d/proj.android
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/src/com/vic/apps/test/app
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/src/com/vic/apps/test/app/androidCocos2d.java
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/bin
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/libs
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/values
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/values/strings.xml
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/layout
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/layout/main.xml
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/drawable-xhdpi
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/drawable-hdpi
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/drawable-mdpi
Created directory /Users/vic/cocos2d-x/androidCocos2d/proj.android/res/drawable-ldpi
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/AndroidManifest.xml
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/build.xml
Added file /Users/vic/cocos2d-x/androidCocos2d/proj.android/proguard-project.txt
Resolved location of library project to: /Users/vic/cocos2d-x/cocos2dx/platform/android/java
Updated project.properties
Updated local.properties
Updated file /Users/vic/cocos2d-x/androidCocos2d/proj.android/proguard-project.txt
vicmatoMacBook:cocos2d-x vic$
2.到创建好的目录(如我创建好的目录中: /Users/vic/cocos2d-x/androidCocos2d/proj.android)下编译c++代码
./build_native.sh
日志:
vicmatoMacBook:proj.android vic$ ./build_native.sh
NDK_ROOT = /Users/vic/android-ndk-r8d
COCOS2DX_ROOT = /Users/vic/cocos2d-x/androidCocos2d/proj.android/../..
APP_ROOT = /Users/vic/cocos2d-x/androidCocos2d/proj.android/..
APP_ANDROID_ROOT = /Users/vic/cocos2d-x/androidCocos2d/proj.android
Using prebuilt externals
make: Entering directory `/Users/vic/cocos2d-x/androidCocos2d/proj.android'
/Users/vic/android-ndk-r8d/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Compile++ thumb : game_shared <= main.cpp
。。
。。
SharedLibrary : libgame.so
Install : libgame.so => libs/armeabi/libgame.so
make: Leaving directory `/Users/vic/cocos2d-x/androidCocos2d/proj.android'
vicmatoMacBook:proj.android vic$
3.导入eclipse中并运行
1)先导入 解压目录/cocos2dx/platform/android/java 中的项目(如果不导入cocos2dx ,导入android cocos2d-x创建的项目就会报错:我这里)
2)在导入刚刚创建好的android项目
3.运行项目 :连接手机或这模拟器就可以run了 下面就是手机中的截图
三)cocos2d-x android helloworld项目已经ok 剩下的游戏方面都交由底层c/c++来进行编写了 这就是cocos2d-x跨平台好处之一