大家好!
在這裏我介紹的是編輯原始的方法,我個人認爲也是比較通用的方法,不管是現在cocos2d-x 2.2 還是cocos2d-x 3.0版本都是一樣的
先來介紹android的編譯過程:
在編譯之前首先要準備幾個東西
1、搭建android開發環境
http://developer.android.com/sdk/index.html 現在android開發環境
在這個工具裏面已經集成了android的開發環境
2、因爲要編譯ndk,所有我們要搭建ndk的編譯環境
首先要去去下載:Cygwin 地址:http://www.programarts.com/cfree_ch/doc/help/UsingCF/CompilerSupport/Cygwin/Cygwin1.htm
其次要去下載:ndk (注意:最好用現在的最新版本) 地址:https://developer.android.com/tools/sdk/ndk/index.html
配置 Cygwin:
找到Cygwin安裝路徑,找到cygwin\home\win7\.bash_profile 找到這個文件打開,在文件末尾加上:
NDK_ROOT=/cygdrive/E/android/android-ndk-r9c(這個你ndk的文件路徑)
export NDK_ROOT
內容如下:
# base-files version 3.9-3
# To pick up the latest recommended .bash_profile content,
# look in /etc/defaults/etc/skel/.bash_profile
# Modifying /etc/skel/.bash_profile directly will prevent
# setup from updating it.
# The copy in your home directory (~/.bash_profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking. If you feel a change
# would be benifitial to all, please feel free to send
# a patch to the cygwin mailing list.
# ~/.bash_profile: executed by bash for login shells.
# source the system wide bashrc if it exists
if [ -e /etc/bash.bashrc ] ; then
source /etc/bash.bashrc
fi
# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
source "${HOME}/.bashrc"
fi
# Set PATH so it includes user's private bin if it exists
# if [ -d "${HOME}/bin" ] ; then
# PATH=${HOME}/bin:${PATH}
# fi
# Set MANPATH so it includes users' private man if it exists
# if [ -d "${HOME}/man" ]; then
# MANPATH=${HOME}/man:${MANPATH}
# fi
# Set INFOPATH so it includes users' private info if it exists
# if [ -d "${HOME}/info" ]; then
# INFOPATH=${HOME}/info:${INFOPATH}
# fi
NDK=/cygdrive/E/android/android-ndk-r9c
export NDK
這個cygwin與ndk的配置就已經完成
測試是否配置成功,可以到:E:\android\android-ndk-r9c\samples\hello-jni 這個目錄下面編譯這個ndk自帶的例子
如果出現這個說明編譯成功了!說明cygwin和ndk的配置已經搭建好了
3、一切已經準備好,我們就開始編譯我們cocos2d-x helloword
打開cygwin,進入/cocos2d-x-2.2.2/samples/Cpp/HelloCpp/proj.android 輸入
這個就開始編譯了: