当前位置:网站首页>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
边栏推荐
- NSQ源码安装运行过程
- Chinese translation of Tagore's floating birds (1~10)
- Getting started with Message Oriented Middleware
- [redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
- [combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
- 切入点表达式
- Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
- 六月 致 -.-- -..- -
- pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
- 坚持输出需要不断学习
猜你喜欢

Function introduction of JMeter thread group

First knowledge of database

Myopia: take off or match glasses? These problems must be understood clearly first
![[statement] about searching sogk1997 and finding many web crawler results](/img/1a/8ed3ca0030ea227adcd95e8b306aca.png)
[statement] about searching sogk1997 and finding many web crawler results

Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14

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

"Remake Apple product UI with Android" (3) - elegant statistical chart

About text selection in web pages and counting the length of selected text

Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
随机推荐
Please be prepared to lose your job at any time within 3 years?
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
跟我学企业级flutter项目:简化框架demo参考
在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
Leetcode binary search tree
手机注册股票开户安全吗 开户需要钱吗
Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
First!! Is lancet hungry? Official documents
用同花顺炒股开户安全吗?
Custom plug-in construction and use of QT plug-in
Detailed explanation of four modes of distributed transaction (Seata)
特征多项式与常系数齐次线性递推
Page dynamics [2]keyframes
Go language self-study series | if else if statement in golang
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
Détails du contrôle de la congestion TCP | 3. Espace de conception
《天天数学》连载56:二月二十五日
The mixlab editing team is recruiting teammates~~
几种常见IO模型的原理
How to use AAB to APK and APK to AAB of Google play apps on the shelves