windows下cocos2dx3.4中打包apk的方法

时间:2023-02-08 18:22:48

1. 新建build_release.bat,首先将res和src拷贝到assets下,然后调用ndk的编译方法。内容如下

rd /s /q assets
xcopy "../../../res" "assets/res" /e /i /h
xcopy "../../../src" "assets/src" /e /i /h

::cocos compile --no-res --compile-script 0 -m release -p android

goto build

:build_error
pause

:build
call %NDK_ROOT%/ndk-build.cmd -j2 NDK_MODULE_PATH=../../cocos2d-x;../../cocos2d-x/cocos/;../../cocos2d-x/external;../../cocos2d-x/cocos/scripting NDK_TOOLCHAIN_VERSION=4.8

if errorlevel 1 goto build_error

call %ANT_ROOT%/ant release
if errorlevel 1 goto build_error

2. 修改ant.properties,设置签名文件所在目录

# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.alias.password=123456
key.store.password=123456
key.store=android-release-key.keystore
key.alias=androidreleasekey


3. 找到工程下面的local.properties,没有则新建一个,写入下面内容(修改sdk路径)。E:\\anroid 目录下面有两个文件夹(adt-bundle-windows-x86-20131030,android-ndk-r9c),没有adt的点击下载(附带android-release-key.keystore)

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=E:\\android\\adt-bundle-windows-x86-20131030\\sdk


4. 利用eclipse生成一个签名文件,命名为android-release-key.keystore

直接运行build_release.bat即可打包apk文件