当前位置:网站首页>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
边栏推荐
- Nifi from introduction to practice (nanny level tutorial) - flow
- [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)
- Caching mechanism of Hibernate / session level caching mechanism
- First!! Is lancet hungry? Official documents
- Function introduction of JMeter thread group
- TCP擁塞控制詳解 | 3. 設計空間
- Develop team OKR in the way of "crowdfunding"
- 特征多项式与常系数齐次线性递推
- Détails du contrôle de la congestion TCP | 3. Espace de conception
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
猜你喜欢
关于网页中的文本选择以及统计选中文本长度
Remote file contains actual operation
Nifi from introduction to practice (nanny level tutorial) - flow
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
From the 18th line to the first line, the new story of the network security industry
Jmeter线程组功能介绍
First knowledge of database
远程文件包含实操
Please be prepared to lose your job at any time within 3 years?
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
随机推荐
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
How to initialize views when loading through storyboards- How is view initialized when loaded via a storyboard?
Explore Cassandra's decentralized distributed architecture
一些事情的反思
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
半监督学习
Mongodb installation and basic operation
Leetcode binary search tree
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
Project -- high concurrency memory pool
Golang 装饰器模式以及在NSQ中的使用
Unity项目优化案例一
Mb10m-asemi rectifier bridge mb10m
[statement] about searching sogk1997 and finding many web crawler results
Page dynamics [2]keyframes
Pychart error updating package list: connect timed out
远程办公之大家一同实现合作编辑资料和开发文档 | 社区征文