COCOS2DX 3.8 Android Packaging script writing

Source: Internet
Author: User
Tags python script

Cocos Integrated Packaging command Cocos compile-p Android

Instead of using this scheme here, write your own script for the following reasons

    1. Scripting in your own hands can be the first time to solve and find bugs
    2. There will always be a variety of customized requirements for the game, and it is impossible for the official to give all the solutions.

For ease of administration and extension we have created two new folders under the project root directory

    1. Build/android: Package Script directory,
    2. PUBLISH/ANDROID:APK Output Directory

Android is packaged in two steps:

    1. Compiling so
    2. Build apk

Compile scripts for so

#!/usr/bin/env bash# set. Bash_profile or. Profileif [-F ~/.bash_profile]; Thenprofile_name=~/.bash_profileelseprofile_name=~/.profilefisource $PROFILE _namedir= "$ (CD" $ (dirname "${BASH_ Source[0]} ")" && pwd) "app_root=" $DIR/.. /.. /.." app_android_root= "$DIR" Export cocos2dx_root= $DIR/. /.. /cocos2d-xexport ndk_debug=1echo "-config:" echo "ndk_root = $NDK _root" echo "cocos2dx_root = $COCOS 2dx_root" E Cho "app_root = $APP _root" echo "app_android_root = $APP _android_root" echo "-cleanup" find "$APP _android_ ROOT "-type D | Xargs chmod 755 $1if [-D "$APP _android_root"/bin]; Then RM-RF "$APP _android_root"/bin/*.apkfimkdir-p "$APP _android_root"/binchmod 755 "$APP _android_root"/binif [-D "$A Pp_android_root "/assets"; Then RM-RF "$APP _android_root"/assets/*fimkdir-p "$APP _android_root"/assetschmod 755 "$APP _android_root"/assets# Bui Ldecho "Using prebuilt externals" "$NDK _root"/ndk-build $ANDROID _ndk_build_flags ndk_debug= $NDK _debug $NDK _build_ FLAGS-C "$APP _android_root" $* "ndk_module_path=${cocos2dx_root}:${cocos2dx_root}/cocos:${cocos2dx_root}/external:${ Cocos2dx_root}/cocos/scripting "

APK generation script: first copy the resources (can be copied according to the actual channel of different resources) code (can be compiled according to the actual project requirements of bytecode and confuse encryption) and ant packaging, if the release package also configure the signature, here is a basic build debug.apk script

build_android.sh

#!/bin/bashprojectpath= "$" dir= "$ (CD" $ (dirname "${bash_source[0]}") "&& pwd" CD ${dir}ant-buildfile ${proje Ctpath}/build.xml

And then write the script call build_android.sh pass parameters, in order to facilitate later extension, here in Python written

# coding=utf-8#!/usr/bin/pythonimport os, shutilimport datetimeclass buildandroid:def __init__ (self): Self.dir = Os.path.split (Os.path.realpath (__file__)) [0] Self.projectpath = ". /.. /frameworks/runtime-src/proj.android "Self.outputpath = Self.dir +"/... /.. /publish/android "Self.rootpath =".        /.."  Self.appname = "XXXXX" def Build (self): Rootrespath = Self.rootpath + "/res/" Rootsrcpath = Self.rootpath + "/src/" Projectrespath = Self.projectpath + "/assets/res/" Projectsrcpath = Self.projectpath + "/assets/s rc/"If Os.path.isdir (Projectrespath): Shutil.rmtree (Projectrespath) if Os.path.isdir (PROJECTSRCP ATH): Shutil.rmtree (Projectsrcpath) shutil.copytree (Rootrespath, Projectrespath) Shutil.copytree ( Rootsrcpath, Projectsrcpath) os.system ("sh build_android.sh" + self.projectpath) if not OS.PATH.ISD IR (Self.outputpath): Os.mkdir (SELF.OUTPUTpath) #获得当前时间 now = Datetime.datetime.now () OutputFile = Self.outputpath + "/" +self.appname + "_" + Now.strftime ("%y%m%d%h%m") + ". apk" Shutil.copy (Self.projectpath + "/bin/" + self.appname + "-debug.apk", OutputFi Le) print ("[Success]" + outputFile) def run (self): Os.chdir (Self.dir) self.build () Buildandroid = Buildandroid () Buildandroid.run ()

  

Such a basic packaging script is written, we can expand the python script according to our own project requirements

COCOS2DX 3.8 Android Packaging script writing

Related Article

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.