-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuildAndroid.py
162 lines (148 loc) · 6.41 KB
/
buildAndroid.py
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# buildAndroid.py
import os
import subprocess
import errno
import shutil
import buildDog
def writeFile(workingDir, packageDir, fileName, outStr, fileExt, packageName):
#print "Path:", packageDir
makeDir(workingDir+packageDir)
fileName += fileExt
fo=open(workingDir+packageDir + os.sep + fileName, 'w')
packageHeader = "package " + packageName + ";\n\n"
outStr = packageHeader + outStr[0][1]
fo.write(outStr)
fo.close()
def runCMD(myCMD, myDir):
print(" COMMAND: ", myCMD, "\n")
pipe = subprocess.Popen(myCMD, cwd=myDir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = pipe.communicate()
if out:
print(" Result: ",out)
if err:
print("\n", err)
if (err.find("ERROR")) >= 0:
exit(1)
return [out, err]
def makeDir(dirToGen):
#print "dirToGen:", dirToGen
try:
os.makedirs(dirToGen)
except OSError as exception:
if exception.errno != errno.EEXIST: raise
def copyTree(src, dst):
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, False, None)
else:
shutil.copy2(s, d)
def copyFile(fileName, src, dst):
s = os.path.join(src, fileName)
d = os.path.join(dst, fileName)
if os.path.isdir(s):
shutil.copytree(s, d, False, None)
else:
shutil.copy2(s, d)
def pathAndroid(workingDir, dirsToGen):
print('-------------------------------- G e n e r a t i n g F o l d e r S t r u c t u r e \n')
makeDir(workingDir)
for dirToGen in dirsToGen:
makeDir(workingDir + dirToGen)
def gradleFile(topDomain, domain, appName, workingDir):
print('-------------------------------- G e n e r a t i n g G r a d l e \n')
fileName = "build.gradle"
outStr = 'buildscript {\n' \
' repositories {\n' \
' mavenCentral()\n' \
' jcenter()\n' \
' google()\n' \
' }\n' \
' dependencies {\n' \
' classpath "com.android.tools.build:gradle:3.6.2"\n' \
' }\n' \
'}\n' \
'apply plugin: "com.android.application"\n' \
'android {\n' \
' compileSdkVersion 28\n' \
' defaultConfig {\n' \
' targetSdkVersion 28\n' \
' minSdkVersion 24\n' \
' }\n' \
' sourceSets {main{res.srcDirs = [\'res\']}}\n'\
' buildTypes {\n' \
' release {\n' \
' minifyEnabled false\n' \
' proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"\n' \
' }\n' \
' }\n' \
'}\n' \
'allprojects {\n' \
' repositories {\n' \
' jcenter()\n' \
' maven {\n' \
' url "https://maven.google.com"\n' \
' }\n' \
' }\n' \
'}\n' \
'dependencies {\n' \
' implementation fileTree(dir: "libs", include: ["*.jar"])\n' \
' implementation "com.android.support:appcompat-v7:24.1.1"\n' \
' implementation "com.android.support:support-v4:24.2.1"\n' \
' implementation "com.android.support:design:24.2.1"\n' \
'}\n' \
fo=open(workingDir + os.sep + fileName, 'w')
fo.write(outStr)
fo.close()
def androidManifest(topDomain, domain, moduleName, labelName, launchIconName, mainDir):
print('-------------------------------- G e n e r a t i n g M a n i f e s t \n')
fileName = "AndroidManifest.xml"
if launchIconName: iconTag = 'android:icon="@drawable/' + launchIconName + '"'
else: iconTag = ''
outStr = '<?xml version="1.0" encoding="utf-8"?>\n' \
'<manifest xmlns:android="http://schemas.android.com/apk/res/android"\n' \
' package="' + topDomain + '.' + domain + '.' + moduleName + '">\n' \
' <application ' + iconTag + ' android:label="' + labelName + '"\n' \
' android:theme="@style/Theme.AppCompat.Light.NoActionBar">\n' \
' <activity android:name="' + moduleName + '">\n' \
' <intent-filter>\n' \
' <action android:name="android.intent.action.MAIN" />\n' \
' <category android:name="android.intent.category.LAUNCHER" />\n' \
' </intent-filter>\n' \
' </activity>\n' \
' </application>\n' \
'</manifest>\n' \
fo=open(mainDir + os.sep + fileName, 'w')
fo.write(outStr)
fo.close()
def AndroidBuilder(debugMode, minLangVersion, fileName, labelName, launchIconName, libFiles, buildName, platform, outStr):
fileExt = '.java'
topDomain = "com"
domain = "infomage"
currentDir = os.getcwd()
workingDir = currentDir + '/' + buildName
moduleName = 'GLOBAL'
packageDir = '/src/main/java/'+topDomain+'/'+domain+'/'+moduleName
assetsDir = '/src/main/assets'
drawableDir = '/res/drawable'
drawablePath = workingDir + drawableDir
packageName = topDomain+'.'+domain+'.'+moduleName
targetPlatform = ""
dirsToGen = [assetsDir, packageDir, drawableDir]
print('Building for Android: ', drawablePath)
pathAndroid(workingDir, dirsToGen)
copyTree("Resources", buildName+assetsDir)
if launchIconName:
launchIconName = launchIconName+'.png'
copyFile(launchIconName, currentDir, drawablePath)
writeFile(workingDir, packageDir, moduleName, outStr, fileExt, packageName)
gradleFile(topDomain, domain, moduleName, workingDir)
androidManifest(topDomain, domain, moduleName, labelName, launchIconName, workingDir+'/src/main')
# TODO: add missing files to workingDir
#[out, err] = runCMD( './gradlew tasks ', workingDir)
#[out, err] = runCMD( './gradlew assembleDebug --stacktrace', workingDir)
#[out, err] = runCMD( './gradlew installDebug ', workingDir)
buildStr=buildDog.getBuildSting("","",platform,buildName)
print(buildStr)
print('Finished Building for Android')