当前位置:网站首页>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
稀罕的话,点个关注哟
边栏推荐
- Large CSV split and merge
- App移动端测试【4】apk的操纵
- MongoDB 的安装和基本操作
- First!! Is lancet hungry? Official documents
- [redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
- 阿飞的期望
- Distributed task scheduling XXL job
- 探索Cassandra的去中心化分布式架构
- Redis在Windows以及Linux系统下的安装
- 程序猿如何快速成长
猜你喜欢

Microservices - load balancing ribbon

Embedded development: seven reasons to avoid open source software

First knowledge of database

From the 18th line to the first line, the new story of the network security industry
![[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)](/img/1f/3dd95522b8d5f03dd763a6779e3db5.jpg)
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)

uploads-labs靶场(附源码分析)(更新中)

Break through 1million, sword finger 2million!

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)

嵌入式开发:避免开源软件的7个理由
![[list to map] collectors Tomap syntax sharing (case practice)](/img/ac/e02deb1cb237806d357a88fb812852.jpg)
[list to map] collectors Tomap syntax sharing (case practice)
随机推荐
Unity项目优化案例一
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
分布式事务(Seata) 四大模式详解
首发!!lancet饿了么官方文档
App mobile terminal test [4] APK operation
高等数学(第七版)同济大学 习题2-1 个人解答
TCP擁塞控制詳解 | 3. 設計空間
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
Go language self-study series | if else statement in golang
TCP拥塞控制详解 | 3. 设计空间
Qt插件之自定义插件构建和使用
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
Detailed explanation of four modes of distributed transaction (Seata)
Is it safe to open an account with flush?
MongoDB 的安装和基本操作
Record a jar package conflict resolution process
利用MySQL中的乐观锁和悲观锁实现分布式锁
Microservice - declarative interface call openfeign