cocos2d-x的proj.android
一、ant打包
1、新建一个local.properties文件,并在文件里面添加内容:sdk.dir=D:/android/android-sdk-windows
2、将这个文件拷贝到各个依赖工程的根目录下去;
3、配置ant.properties
key.store=../../key.keystore PS:此处要用斜杠“/”,而不是反斜杠“\”。
key.store.password=*****
key.alias=***
key.alias.password=*****
4、运行build.xml进行打包
当前目录下,alt+d(快捷键)--cmd,键入ant,会提示各种命令
>ant debug //打一个debug的包
>ant release //打一个released的包
5、如果没有报错,那么包已经打完了,并且在bin目录下
PS:此处是用到了android自带的build.xml文件。在../android-sdk-windows/tools/ant 目录下
二、python
上面的打包方式只是打出apk包,倘若我们有修改底层c++代码,我们还需要先在cygwin下面执行:./build_native.sh。然后再执行ant。因为再用上python,实现自动编译c++底层代码。也为之后的批量打包打基础。
1、新建一个build.py文件,里面的内容为:
# -*- coding: utf-8 -*-
import os, sys, md5
import ConfigParser
# 配置文件
CONFIG_FILE = 'build.ini'
def read_ndk_root():
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE)
ndk_root = config.get('tools','android_ndk_root')
if ndk_root == '':
print u'请配置NDK路径!\n例如:android_ndk_root = D:/android-ndk-r9\n'
return ndk_root
def read_sdk_root():
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE)
sdk_root = config.get('tools','android_sdk_root')
if sdk_root == '':
print u'请配置 Android SDK 路径!\n例如:android_sdk_root = D:/androidsdk\n'
return sdk_root
def read_project_path():
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE)
project_path = config.get('project_path','project_root')
if project_path == '':
print u'请配置工程目录!\n例如:project_root = D:/workspace/project1/android\n'
return project_path
#编译C++部分
def build_cpp():
cmd_ndk_build = os.path.join(read_project_path(), 'build_native.sh')
if not os.path.exists(cmd_ndk_build):
print u'build_native.sh不存在!!!'
quit()
os.system('bash build_native.sh')
#打包
def export_signed_apk():
build_file = os.path.join(read_project_path(), 'build.xml')
if not os.path.exists(build_file):
print u'build.xml不存在!!!'
quit()
os.system('ant debug')
def read_config():
is_config_ok = True
if read_ndk_root() == '':
is_config_ok = False
if read_sdk_root() == '':
is_config_ok = False
if read_project_path() == '':
is_config_ok = False
if is_config_ok == False:
quit()
def create_config_file():
config = ConfigParser.ConfigParser()
config.add_section('tools')
config.set('tools', 'android_ndk_root', '')
config.set('tools', 'android_sdk_root', '')
config.add_section('project_path')
config.set('project_path', 'project_root', '')
config.write(open(CONFIG_FILE, 'w'))
def check_config_file():
if os.path.exists(CONFIG_FILE):
read_config()
else:
create_config_file()
print u'【请先配置好%s再运行本脚本】' % CONFIG_FILE
print u'NDK的路径:android_ndk_root = D:/android-ndk-r9'
print u'Android SDK的路径:android_sdk_root = D:/androidsdk'
print u'要打包的工程的路径:project_root = D:/workspace/project1/android'
quit()
def main():
check_config_file()
#build_classes_dex()
build_cpp()
export_signed_apk()
if __name__ == '__main__':
main()
2、运行build.py脚本,前提是安装了python环境。
当前目录下,alt+d(快捷键)--cmd
>python build.py //第一次执行的时候会提示配置文件目录,按提示操作就行。提示BUILD SUCCESSFUL就是编译打包成功。