-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.gradle
More file actions
85 lines (74 loc) · 2.93 KB
/
release.gradle
File metadata and controls
85 lines (74 loc) · 2.93 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
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
def ANDROID_MANIFEST_PATH = 'src/main/AndroidManifest.xml'
def getMainActivity = { file ->
new XmlSlurper().parse(file).application.activity.find {
it.'intent-filter'.find { filter ->
filter.action.find {
it.'@android:name'.text() == 'android.intent.action.MAIN'
} && filter.category.find {
it.'@android:name'.text() == 'android.intent.category.LAUNCHER'
}
}
}.'@android:name'
}
project.android.applicationVariants.all { variant ->
def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = "Linbridge"
}
def artifactName
variant.outputs.all { output ->
outputFileName = "${appName}-${output.baseName}-${variant.versionName}.apk"
artifactName = outputFileName
}
variant.assemble.doLast {
def buildType = variant.buildType.name
if (buildType == 'release') {
def outputPath = ["${rootDir}/app/release", "${buildDir}/outputs/apk/release"]
def mainActivity = System.getenv("MAIN_ACTIVITY")
if (mainActivity == null || mainActivity.isEmpty()) {
mainActivity = getMainActivity(file(ANDROID_MANIFEST_PATH))
if (mainActivity != null && !(mainActivity as String).isEmpty()) {
if (!(mainActivity as String).contains(project.android.defaultConfig.applicationId)) {
mainActivity = project.android.defaultConfig.applicationId + mainActivity
}
} else {
mainActivity = project.android.defaultConfig.applicationId
}
}
def content = """
{
"package_name": "${project.android.defaultConfig.applicationId}",
${
if (mainActivity != null)
"\"main_activity\": \"${mainActivity}\","
else ""
}
${
if (artifactName != null) "\"artifact\": \"${artifactName}\","
else ""
}
"version": {
"code": "${project.android.defaultConfig.versionCode}",
"name": "${project.android.defaultConfig.versionName}"
}
}
"""
def slurped = new JsonSlurper().parseText(content)
def builder = new JsonBuilder(slurped)
if (file(outputPath[0]).isDirectory()) {
file("${outputPath[0]}/output.json").write(
builder.toPrettyString()
)
} else {
file("${outputPath[1]}/output.json").write(
builder.toPrettyString()
)
}
}
}
}