-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApkBuild.py
More file actions
134 lines (114 loc) · 4.39 KB
/
Copy pathApkBuild.py
File metadata and controls
134 lines (114 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/python
# coding=utf-8
import zipfile
import shutil
import os
import os.path
import time
import datetime
import sys
# include AppInfo.py
# sys.path.append('./common')
import AppInfo
o_path = os.getcwd() # 返回当前工作目录
# 当前工作目录 Common/PythonCreator/ProjectConfig/Script
sys.path.append('../../')
sys.path.append('./')
from Config.Config import mainConfig
from Common import Source
from Config.AdConfig import mainAdConfig
from Project.Resource import mainResource
from Common.File.FileUtil import FileUtil
from AppInfo.AppChannel import mainAppChannel
from Common.Platform import Platform
class ApkBuild():
builder:None
listChannel = []
def BuildClean(self):
targetDir = mainResource.GetRootDirAndroidStudio()
# build
dir2 = targetDir + "/build"
flag = os.path.exists(dir2)
if flag:
shutil.rmtree(dir2)
print("apk_build_clean sucess")
def BuildApk(self):
if Platform.isWindowsSystem():
# dir1 = "C:\Program Files\Android\Android Studio\gradle"
dir2 = "C:/moon/gradle/gradle-4.10.1"
flag = os.path.exists(dir2)
if not flag:
# shutil.copytree(dir1,dir2)
dir2 = "E:/Program Files/Android/Android Studio/gradle/gradle-4.10.1"
flag = os.path.exists(dir2)
if not flag:
# aliyun
dir2 = "C:/Program Files/Unity/Hub/Editor/"+source.UNITY_VERSION_WIN+"/Editor/Data/PlaybackEngines/AndroidPlayer/Tools/gradle"
os.system(dir2+"/bin/gradle assembleRelease")
else:
# dir2 = "/Users/moon/sourcecode/gradle/gradle-4.10.1/bin"
dir2 = "/Users/moon/sourcecode/gradle/bin"
flag = os.path.exists(dir2)
if flag:
# os.system("chmod 777 "+dir2+"/gradle")
os.system(dir2+"/gradle assembleRelease")
else:
os.system("gradle assembleRelease")
def GetApk(self,channel,isHd):
gameName = mainResource.getGameName()
gameType = mainResource.getGameType()
# copy2 同时复制文件权限
dirapk = mainResource.GetProjectOutPutApp() + "/apk"
if isHd:
dirapk+="/heng"
gameName += "_hd"
else:
dirapk+="/shu"
return dirapk + "/" +gameType + "_" + gameName + "_" + channel + ".apk"
def CopyApk(self,channel):
gameName = mainResource.getGameName()
gameType = mainResource.getGameType()
# copy2 同时复制文件权限
dirapk = mainResource.GetProjectOutPutApp() + "/apk"
if mainResource.AppForPad(False):
dirapk+="/heng"
gameName += "_hd"
else:
dirapk+="/shu"
if not os.path.exists(dirapk):
os.makedirs(dirapk)
shutil.copy2(mainResource.getAndroidProjectApk(), dirapk + "/" +
gameType + "_" + gameName + "_" + channel + ".apk")
def Init(self,channel):
self.listChannel.clear()
if channel==Source.HUAWEI:
self.listChannel.append(Source.HUAWEI)
if channel==Source.TAPTAP:
self.listChannel.append(Source.TAPTAP)
if channel==Source.GP:
self.listChannel.append(Source.GP)
if channel=="all":
self.listChannel.append(Source.HUAWEI)
self.listChannel.append(Source.TAPTAP)
self.listChannel.append(Source.GP)
# 主函数的实现
def Run(self,channel,isHD):
self.Init(channel)
gameName = mainResource.getGameName()
gameType = mainResource.getGameType()
print("ApkBuild isHD="+str(isHD))
print("gameName="+gameName)
print ("gameType="+gameType)
print(mainResource.getAndroidProjectApk())
# python 里无法直接执行cd目录,想要用chdir改变当前的工作目录
android_studio_dir = mainResource.GetRootDirAndroidStudioGame()
# python 里无法直接执行cd目录,要用chdir改变当前的工作目录
os.chdir(android_studio_dir)
for channel in self.listChannel:
print("apk_build:" + channel)
self.BuildClean()
mainAppChannel.UpdateChannel(channel,isHD)
self.BuildApk()
self.CopyApk(channel)
print("apk_build sucess channel="+channel)
mainApkBuild = ApkBuild()