forked from LSPosed/LSPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApksignPlugin.kt
76 lines (72 loc) · 2.97 KB
/
ApksignPlugin.kt
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
package org.lsposed.lsplugin
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.api.AndroidBasePlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File
private open class ApksignExtensionImpl(private val project: Project) : ApksignExtension {
private var storeFile: File? = null
private var storePassword: String? = null
private var keyAlias: String? = null
private var keyPassword: String? = null
private var config = false
override var storeFileProperty: String? = null
set(value) {
field = value
storeFile = (project.properties.getOrDefault(value, null) as? String?)?.let { project.rootProject.file(it) }
maybeConfig()
}
override var storePasswordProperty: String? = null
set(value) {
field = value
storePassword = project.properties.getOrDefault(value, null) as? String?
maybeConfig()
}
override var keyAliasProperty: String? = null
set(value) {
field = value
keyAlias = project.properties.getOrDefault(value, null) as? String?
maybeConfig()
}
override var keyPasswordProperty: String? = null
set(value) {
field = value
keyPassword = project.properties.getOrDefault(value, null) as? String?
maybeConfig()
}
private fun maybeConfig() {
if (storeFileProperty == null || storePasswordProperty == null || keyAliasProperty == null || keyPasswordProperty == null || config) return
config = true
project.plugins.withType(AndroidBasePlugin::class.java) {
project.extensions.configure(ApplicationExtension::class.java) {
if (storeFile?.exists() == true) {
signingConfigs {
val sign = create("apksign") {
storeFile = [email protected]
storePassword = [email protected]
keyAlias = [email protected]
keyPassword = [email protected]
}
buildTypes {
all {
signingConfig = sign
}
}
}
} else {
println("Apksign fallbacks to use debug signature as ${storeFile?.absolutePath} does not exist")
buildTypes {
all {
signingConfig = signingConfigs.getByName("debug")
}
}
}
}
}
}
}
class ApksignPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.extensions.create(ApksignExtension::class.java, "apksign", ApksignExtensionImpl::class.java, project)
}
}