-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
172 lines (151 loc) · 6.17 KB
/
build.gradle.kts
File metadata and controls
172 lines (151 loc) · 6.17 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
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
163
164
165
166
167
168
169
170
171
172
import com.android.build.api.dsl.ApplicationDefaultConfig
import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.api.AndroidBasePlugin
import com.ncorti.ktfmt.gradle.tasks.KtfmtFormatTask
import java.io.ByteArrayOutputStream
import javax.inject.Inject
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.process.ExecOperations
plugins {
alias(libs.plugins.agp.lib) apply false
alias(libs.plugins.agp.app) apply false
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.ktfmt)
}
/** A ValueSource that executes 'git rev-list --count' to get the total commit count. */
abstract class GitCommitCountValueSource : ValueSource<String, ValueSourceParameters.None> {
@get:Inject abstract val execOperations: ExecOperations
override fun obtain(): String {
val output = ByteArrayOutputStream()
val result =
execOperations.exec {
commandLine("git", "rev-list", "--count", "refs/remotes/origin/master")
standardOutput = output
isIgnoreExitValue = true
}
// Return the count if successful, otherwise a default of "1".
return if (result.exitValue == 0 && output.toString().isNotBlank()) {
output.toString().trim()
} else {
"1"
}
}
}
/** A ValueSource that executes 'git tag' to get the latest version tag. */
abstract class GitLatestTagValueSource : ValueSource<String, ValueSourceParameters.None> {
@get:Inject abstract val execOperations: ExecOperations
override fun obtain(): String {
val output = ByteArrayOutputStream()
val result =
execOperations.exec {
commandLine("git", "tag", "--list", "--sort=-v:refname")
standardOutput = output
isIgnoreExitValue = true
}
// If successful, parse the first line. Provide a default if no tags are found.
return if (result.exitValue == 0 && output.toString().isNotBlank()) {
output.toString().lineSequence().first().removePrefix("v")
} else {
"1.0"
}
}
}
// This defers the execution of the git commands and allows Gradle to cache the results.
val versionCodeProvider by extra(providers.of(GitCommitCountValueSource::class.java) {})
val versionNameProvider by extra(providers.of(GitLatestTagValueSource::class.java) {})
val injectedPackageName by extra("com.android.shell")
val injectedPackageUid by extra(2000)
val defaultManagerPackageName by extra("org.lsposed.manager")
val androidTargetSdkVersion by extra(36)
val androidMinSdkVersion by extra(27)
val androidBuildToolsVersion by extra("36.0.0")
val androidCompileSdkVersion by extra(36)
val androidCompileNdkVersion by extra("29.0.13113456")
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)
subprojects {
plugins.withType(AndroidBasePlugin::class.java) {
extensions.configure(CommonExtension::class.java) {
compileSdk = androidCompileSdkVersion
ndkVersion = androidCompileNdkVersion
buildToolsVersion = androidBuildToolsVersion
buildFeatures { buildConfig = true }
externalNativeBuild {
cmake {
version = "3.29.8+"
buildStagingDirectory = layout.buildDirectory.get().asFile
}
}
defaultConfig {
minSdk = androidMinSdkVersion
ndk { abiFilters.addAll(listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64")) }
if (this is ApplicationDefaultConfig) {
targetSdk = androidTargetSdkVersion
versionCode = versionCodeProvider.get().toInt()
versionName = versionNameProvider.get()
}
val flags =
listOf(
"-DVERSION_CODE=${versionCodeProvider.get()}",
"-DVERSION_NAME='\"${versionNameProvider.get()}\"'",
)
val args =
listOf(
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DVECTOR_ROOT=${rootDir.absolutePath}",
// Enforce 16 KB page size alignment for Android 15+ compatibility
"-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=16384",
"-DCMAKE_EXE_LINKER_FLAGS=-Wl,-z,max-page-size=16384",
)
externalNativeBuild {
cmake {
cFlags.addAll(flags)
cppFlags.addAll(flags)
arguments.addAll(args)
}
}
}
buildTypes {
getByName("release") {
externalNativeBuild {
cmake {
arguments.add(
"-DDEBUG_SYMBOLS_PATH=${
layout.buildDirectory.dir("symbols").get().asFile.absolutePath
}"
)
}
}
}
}
lint {
abortOnError = true
checkReleaseBuilds = false
}
compileOptions {
sourceCompatibility = androidSourceCompatibility
targetCompatibility = androidTargetCompatibility
}
}
}
plugins.withType(JavaPlugin::class.java) {
extensions.configure(JavaPluginExtension::class.java) {
sourceCompatibility = androidSourceCompatibility
targetCompatibility = androidTargetCompatibility
}
}
}
tasks.register<KtfmtFormatTask>("format") {
source = project.fileTree(rootDir)
include(
"*.gradle.kts",
"*/build.gradle.kts",
"hiddenapi/*/build.gradle.kts",
"services/*-service/build.gradle.kts",
)
dependsOn(":daemon:ktfmtFormat")
dependsOn(":xposed:ktfmtFormat")
dependsOn(":zygisk:ktfmtFormat")
}
ktfmt { kotlinLangStyle() }