-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsign-external-init.groovy
52 lines (49 loc) · 1.44 KB
/
sign-external-init.groovy
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
// Android-gradle external signing.
// This allows an external signing service to be used by providing
// a closure in a file given by -PsigningClosure.
// Example:
// void signingFunction(project, variant, output) {
// // Sign output.outputFile somehow.
// }
// ext.sign = this.&signingFunction
//
import org.gradle.api.Project
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
projectsEvaluated {
ext.applySigning = {
if (project.hasProperty('android') &&
android.hasProperty('applicationVariants')) {
project.android.applicationVariants.all { variant ->
signApk(project, variant)
if (null != variant.testVariant) {
signApk(project, variant.testVariant)
}
}
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applySigning
} else {
rootProject.subprojects applySigning
}
}
void signApk(final Project project, final Object variant) {
variant.assemble.doLast {
variant.outputs.each { output ->
if (project.hasProperty('signingClosure')) {
apply from:project.signingClosure
sign(project, variant, output)
} else {
project.logger.log(LogLevel.WARN, 'No signing closure supplied.')
}
}
}
}