当前位置:网站首页>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
边栏推荐
- Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
- Remote file contains actual operation
- Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
- How to use AAB to APK and APK to AAB of Google play apps on the shelves
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
- TCP擁塞控制詳解 | 3. 設計空間
- Please be prepared to lose your job at any time within 3 years?
- Hibernate的缓存机制/会话级缓存机制
- [system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
- nifi从入门到实战(保姆级教程)——flow
猜你喜欢
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
Remote file contains actual operation
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
First knowledge of database
[web security] - [SQL injection] - error detection injection
深入理解 SQL 中的 Grouping Sets 语句
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
How can technology managers quickly improve leadership?
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
Mongodb installation and basic operation
随机推荐
突破100万,剑指200万!
Remote file contains actual operation
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Deep understanding of grouping sets statements in SQL
手机注册股票开户安全吗 开户需要钱吗
LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
Extraction of the same pointcut
Initial test of scikit learn Library
EditText request focus - EditText request focus
Unreal_DataTable 实现Id自增与设置RowName
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
Eleven requirements for test management post
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
阿飞的期望
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
Unity project optimization case 1
Create gradle project
Reflection on some things
特征多项式与常系数齐次线性递推
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装