当前位置:网站首页>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
边栏推荐
- Redis installation under windows and Linux systems
- Initial test of scikit learn Library
- 手机注册股票开户安全吗 开户需要钱吗
- MongoDB 的安装和基本操作
- Stm32f103c8t6 firmware library lighting
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
- EditText request focus - EditText request focus
- PHP中register_globals参数设置
- [statement] about searching sogk1997 and finding many web crawler results
- Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
猜你喜欢

TCP congestion control details | 3 design space

ThreeJS 第二篇:顶点概念、几何体结构
![[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree](/img/cd/00954b9c592c253d42e6a3b8298999.jpg)
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree

初试scikit-learn库

Explore Cassandra's decentralized distributed architecture

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

Break through 1million, sword finger 2million!

Shell script import and export data

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

Brush questions -- sword finger offer
随机推荐
六月 致 -.-- -..- -
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Develop team OKR in the way of "crowdfunding"
Expression of request header in different countries and languages
[list to map] collectors Tomap syntax sharing (case practice)
深入理解 SQL 中的 Grouping Sets 语句
Low level version of drawing interface (explain each step in detail)
Shell script import and export data
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
Construction practice camp - graduation summary of phase 6
近视:摘镜or配镜?这些问题必须先了解清楚
Go language self-study series | if else if statement in golang
Unity项目优化案例一
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Detailed explanation of four modes of distributed transaction (Seata)
MongoDB 的安装和基本操作
坚持输出需要不断学习
Go language self-study series | golang switch statement
用同花顺炒股开户安全吗?
How to thicken the brush in the graphical interface