当前位置:网站首页>Cocos Creator 2.x 自动打包(构建 + 编译)
Cocos Creator 2.x 自动打包(构建 + 编译)
2022-07-03 16:09:00 【木限东】
打包(android 打包 apk,iOS 打包 ipa),使用 Cocos Creator 构建编译,如果通过构建面板的话,每次都要启动 Cocos Creator 编辑器,打开构建面板,然后按构建按钮等等操作,太麻烦了。
Cocos Creator 其实提供命令行构建和编译的方式。https://docs.cocos.com/creator/2.4/manual/zh/publish/publish-in-command-line.html
这样子就好办多了,我们使用 python 工具来配置命令行打包即可,操作很简单。
Windows 操作平台
1、切换到当前 python 脚本的路径(这样子你的脚本就可以放到电脑上的任意位置啦)
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
2、把命令行中的构建参数模拟出来,使用 os.system 来执行
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('CocosCreator.exe --path %s --build "%s"' %(project_path, build_args))
3、编译项目,使用 os.system 来执行
compile_args = 'platform=' + platform
os.system('CocosCreator.exe --path %s --compile "%s"' %(project_path, compile_args))
完整的代码
import os
from string import Template
import platform
import json
global config
build_args_array = []
def load_json(file_name):
with open(file_name, "r") as f:
data = json.load(f)
return data
if __name__ == '__main__':
global config
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
config = load_json("config.json")
creator_exe_path = config["creator_exe_path"]
os.chdir(creator_exe_path)
project_path = config["project_path"]
platform = config["platform"]
build_path = config["buildPath"]
print("----------------------开始构建-------------")
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('CocosCreator.exe --path %s --build "%s"' %(project_path, build_args))
print("----------------------构建完成-------------")
print("----------------------开始编译-------------")
compile_args = 'platform=' + platform
os.system('CocosCreator.exe --path %s --compile "%s"' %(project_path, compile_args))
print("----------------------编译完成-------------")
file_generate_path = project_path + "/" + build_path + '/jsb-link/publish'
print("编译构建后的" + platform + "路径:" + file_generate_path)
macOS 平台
1、切换到当前 python 脚本的路径(这样子你的脚本就可以放到电脑上的任意位置啦)
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
2、把命令行中的构建参数模拟出来,使用 os.system 来执行
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('./CocosCreator --path %s --build "%s"' %(project_path, build_args))
3、编译项目,使用 os.system 来执行
compile_args = 'platform=' + platform
os.system('./CocosCreator --path %s --compile "%s"' %(project_path, compile_args))
完整的代码
#!/usr/bin/python
#coding=utf-8
import os
from string import Template
import platform
import json
build_args_array = []
def load_json(file_name):
with open(file_name, "r") as f:
data = json.load(f)
return data
if __name__ == '__main__':
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
config = load_json("config.json")
creator_app_path = config["creator_app_path"]
os.chdir(creator_app_path)
os.system("pwd")
project_path = config["project_path"]
platform = config["platform"]
build_path = config["buildPath"]
encryptJs = config["encryptJs"]
apiLevel = config["apiLevel"]
configPath = scriptRoot + "/build_config.json"
print("----------------------开始构建-------------")
build_args = "platform=" + platform + ";configPath=" + configPath + ";encryptJs=" + encryptJs
os.system('./CocosCreator --path %s --build "%s"' %(project_path, build_args))
print("----------------------构建完成-------------")
print("----------------------开始编译-------------")
compile_args = "platform=" + platform + ";buildPath=" + build_path + ";apiLevel=" + apiLevel + ";configPath=" + configPath
os.system('./CocosCreator --path %s --compile "%s"' %(project_path, compile_args))
file_generate_path = project_path + "/" + build_path + '/jsb-link/publish'
print(file_generate_path)
print("----------------------编译完成-------------")
是不是自动打包很简单呢?赶快试一试吧
PS:可以通过以下链接,下载源代码
macOS打包:https://gitee.com/yeshao2069/cocos-creator-plugin/tree/other/cocos-pack/cocos-pack-mac-2x
Windows打包:https://gitee.com/yeshao2069/cocos-creator-plugin/tree/other/cocos-pack/cocos-pack-win-2x
稀罕的话,点个关注哟
边栏推荐
- Go language self-study series | if else statement in golang
- 请求头不同国家和语言的表示
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
- 面试官:JVM如何分配和回收堆外内存
- Golang 装饰器模式以及在NSQ中的使用
- Shell script import and export data
- Download and install common programs using AUR
- Large CSV split and merge
- Redis installation under windows and Linux systems
- June to - -------
猜你喜欢
![[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)](/img/68/3721975cf33fcfacc28dc4d3d6a5ca.jpg)
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)

ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装

“用Android复刻Apple产品UI”(3)—优雅的数据统计图表

Microservice sentinel flow control degradation

The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)

记一次jar包冲突解决过程

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
![[web security] - [SQL injection] - error detection injection](/img/18/5c511871dab0e5c684b6b4c081c061.jpg)
[web security] - [SQL injection] - error detection injection

Project -- high concurrency memory pool

Détails du contrôle de la congestion TCP | 3. Espace de conception
随机推荐
0214-27100 a day with little fluctuation
SVN使用规范
[combinatorics] combinatorial identity (sum of combinatorial identity products 1 | sum of products 1 proof | sum of combinatorial identity products 2 | sum of products 2 proof)
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
App mobile terminal test [4] APK operation
工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!
阿飞的期望
Golang 装饰器模式以及在NSQ中的使用
关于网页中的文本选择以及统计选中文本长度
Go language self-study series | golang switch statement
Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
Shell script import and export data
高等数学(第七版)同济大学 习题2-1 个人解答
Microservice - fuse hystrix
架构实战营 - 第 6 期 毕业总结
Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
App mobile terminal test [3] ADB command
Microservice API gateway zuul
Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
Microservice API gateway