当前位置:网站首页>Cocos Creator 2. X automatic packaging (build + compile)
Cocos Creator 2. X automatic packaging (build + compile)
2022-07-03 16:19:00 【Muqidong】
pack (android pack apk,iOS pack ipa), Use Cocos Creator Build build build , If you build panels , Start every time Cocos Creator Editor , Open the build panel , Then press the build button and so on , It's too troublesome .
Cocos Creator In fact, it provides a way to build and compile the command line .https://docs.cocos.com/creator/2.4/manual/zh/publish/publish-in-command-line.html
It's much easier to do this , We use python Tools to configure command line packaging , Easy to operate .
Windows Operating platform
1、 Switch to current python The path of the script ( In this way, your script can be placed anywhere on the computer )
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
2、 Simulate the build parameters in the command line , Use os.system To execute
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('CocosCreator.exe --path %s --build "%s"' %(project_path, build_args))
3、 Compile the project , Use os.system To execute
compile_args = 'platform=' + platform
os.system('CocosCreator.exe --path %s --compile "%s"' %(project_path, compile_args))
Complete code
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("---------------------- Begin to build -------------")
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('CocosCreator.exe --path %s --build "%s"' %(project_path, build_args))
print("---------------------- Build complete -------------")
print("---------------------- Start compilation -------------")
compile_args = 'platform=' + platform
os.system('CocosCreator.exe --path %s --compile "%s"' %(project_path, compile_args))
print("---------------------- Compile the complete -------------")
file_generate_path = project_path + "/" + build_path + '/jsb-link/publish'
print(" Compiled and built " + platform + " route :" + file_generate_path)
macOS platform
1、 Switch to current python The path of the script ( In this way, your script can be placed anywhere on the computer )
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
os.chdir(scriptRoot)
2、 Simulate the build parameters in the command line , Use os.system To execute
build_args = 'platform=' + platform + ";buildPath=" + build_path
os.system('./CocosCreator --path %s --build "%s"' %(project_path, build_args))
3、 Compile the project , Use os.system To execute
compile_args = 'platform=' + platform
os.system('./CocosCreator --path %s --compile "%s"' %(project_path, compile_args))
Complete code
#!/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("---------------------- Begin to build -------------")
build_args = "platform=" + platform + ";configPath=" + configPath + ";encryptJs=" + encryptJs
os.system('./CocosCreator --path %s --build "%s"' %(project_path, build_args))
print("---------------------- Build complete -------------")
print("---------------------- Start compilation -------------")
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("---------------------- Compile the complete -------------")
Is it easy to pack automatically ? Give it a try
PS: You can go through the following link , Download source code
macOS pack :https://gitee.com/yeshao2069/cocos-creator-plugin/tree/other/cocos-pack/cocos-pack-mac-2x
Windows pack :https://gitee.com/yeshao2069/cocos-creator-plugin/tree/other/cocos-pack/cocos-pack-win-2x
Rare words , Let's pay attention
边栏推荐
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Mongodb installation and basic operation
- Redis high availability and persistence
- Create gradle project
- TCP拥塞控制详解 | 3. 设计空间
- Mixlab编辑团队招募队友啦~~
- Client does not support authentication protocol requested by server; consider upgrading MySQL client
- 突破100万,剑指200万!
- nifi从入门到实战(保姆级教程)——flow
- uploads-labs靶场(附源码分析)(更新中)
猜你喜欢

Redis installation under windows and Linux systems

"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation

ThreeJS 第二篇:顶点概念、几何体结构

Remote file contains actual operation

跟我学企业级flutter项目:简化框架demo参考
![[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)

Three dimensional reconstruction of deep learning

MB10M-ASEMI整流桥MB10M

Myopia: take off or match glasses? These problems must be understood clearly first

Please be prepared to lose your job at any time within 3 years?
随机推荐
Principles of several common IO models
MongoDB 的安装和基本操作
About text selection in web pages and counting the length of selected text
MB10M-ASEMI整流桥MB10M
Is it safe to open an account with tongdaxin?
Multithread 02 thread join
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
相同切入点的抽取
How can technology managers quickly improve leadership?
Qt插件之自定义插件构建和使用
Pychart error updating package list: connect timed out
nifi从入门到实战(保姆级教程)——flow
Leetcode binary search tree
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Golang 装饰器模式以及在NSQ中的使用
Break through 1million, sword finger 2million!
Eleven requirements for test management post
Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
“用Android复刻Apple产品UI”(3)—优雅的数据统计图表
pycharm错Error updating package list: connect timed out