Skip to content

Commit b3050ce

Browse files
authored
Refactor build system and modularize package configurations (#555)
- Clean up Gradle configurations, apply formatting, and rename project to Vector. - Replace hardcoded package names and UIDs with dynamic BuildConfig and CMake macros. - Remove unused project files and stubs. - Upgrade Kotlin and AndroidX dependencies.
1 parent bee5f2e commit b3050ce

26 files changed

Lines changed: 194 additions & 413 deletions

File tree

app/build.gradle.kts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ android {
6969
}
7070
}
7171

72-
sourceSets {
73-
named("main") {
74-
res {
75-
srcDirs("src/common/res")
76-
}
77-
}
78-
}
72+
sourceSets { named("main") { res { srcDirs("src/common/res") } } }
7973
namespace = defaultManagerPackageName
8074
}
8175

@@ -88,27 +82,28 @@ autoResConfig {
8882

8983
materialThemeBuilder {
9084
themes {
91-
for ((name, color) in listOf(
92-
"Red" to "F44336",
93-
"Pink" to "E91E63",
94-
"Purple" to "9C27B0",
95-
"DeepPurple" to "673AB7",
96-
"Indigo" to "3F51B5",
97-
"Blue" to "2196F3",
98-
"LightBlue" to "03A9F4",
99-
"Cyan" to "00BCD4",
100-
"Teal" to "009688",
101-
"Green" to "4FAF50",
102-
"LightGreen" to "8BC3A4",
103-
"Lime" to "CDDC39",
104-
"Yellow" to "FFEB3B",
105-
"Amber" to "FFC107",
106-
"Orange" to "FF9800",
107-
"DeepOrange" to "FF5722",
108-
"Brown" to "795548",
109-
"BlueGrey" to "607D8F",
110-
"Sakura" to "FF9CA8"
111-
)) {
85+
for ((name, color) in
86+
listOf(
87+
"Red" to "F44336",
88+
"Pink" to "E91E63",
89+
"Purple" to "9C27B0",
90+
"DeepPurple" to "673AB7",
91+
"Indigo" to "3F51B5",
92+
"Blue" to "2196F3",
93+
"LightBlue" to "03A9F4",
94+
"Cyan" to "00BCD4",
95+
"Teal" to "009688",
96+
"Green" to "4FAF50",
97+
"LightGreen" to "8BC3A4",
98+
"Lime" to "CDDC39",
99+
"Yellow" to "FFEB3B",
100+
"Amber" to "FFC107",
101+
"Orange" to "FF9800",
102+
"DeepOrange" to "FF5722",
103+
"Brown" to "795548",
104+
"BlueGrey" to "607D8F",
105+
"Sakura" to "FF9CA8",
106+
)) {
112107
create("Material$name") {
113108
lightThemeFormat = "ThemeOverlay.Light.%s"
114109
darkThemeFormat = "ThemeOverlay.Dark.%s"

build.gradle.kts

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import org.gradle.api.provider.ValueSourceParameters
99
import org.gradle.process.ExecOperations
1010

1111
plugins {
12-
alias(libs.plugins.lsplugin.cmaker)
13-
alias(libs.plugins.lsplugin.jgit)
1412
alias(libs.plugins.agp.lib) apply false
1513
alias(libs.plugins.agp.app) apply false
16-
alias(libs.plugins.nav.safeargs) apply false
1714
alias(libs.plugins.kotlin) apply false
1815
alias(libs.plugins.ktfmt)
1916
}
@@ -64,43 +61,9 @@ abstract class GitLatestTagValueSource : ValueSource<String, ValueSourceParamete
6461
val versionCodeProvider by extra(providers.of(GitCommitCountValueSource::class.java) {})
6562
val versionNameProvider by extra(providers.of(GitLatestTagValueSource::class.java) {})
6663

67-
val repo = jgit.repo()
68-
val commitCount = (repo?.commitCount("refs/remotes/origin/master") ?: 1) + 4200
69-
val latestTag = repo?.latestTag?.removePrefix("v") ?: "1.0"
70-
7164
val injectedPackageName by extra("com.android.shell")
7265
val injectedPackageUid by extra(2000)
73-
7466
val defaultManagerPackageName by extra("org.lsposed.manager")
75-
val verCode by extra(commitCount)
76-
val verName by extra(latestTag)
77-
78-
cmaker {
79-
default {
80-
arguments.addAll(
81-
arrayOf("-DVECTOR_ROOT=${rootDir.absolutePath}", "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON")
82-
)
83-
val flags =
84-
arrayOf(
85-
"-DINJECTED_UID=$injectedPackageUid",
86-
"-DVERSION_CODE=${verCode}",
87-
"-DVERSION_NAME='\"${verName}\"'",
88-
"-Wno-gnu-string-literal-operator-template",
89-
"-Wno-c++2b-extensions",
90-
)
91-
cFlags.addAll(flags)
92-
cppFlags.addAll(flags)
93-
abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
94-
}
95-
buildTypes {
96-
if (it.name == "release") {
97-
arguments +=
98-
"-DDEBUG_SYMBOLS_PATH=${
99-
layout.buildDirectory.dir("symbols").get().asFile.absolutePath
100-
}"
101-
}
102-
}
103-
}
10467

10568
val androidTargetSdkVersion by extra(36)
10669
val androidMinSdkVersion by extra(27)
@@ -110,15 +73,14 @@ val androidCompileNdkVersion by extra("29.0.13113456")
11073
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
11174
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)
11275

113-
tasks.register("Delete", Delete::class) { delete(rootProject.layout.buildDirectory) }
114-
11576
subprojects {
11677
plugins.withType(AndroidBasePlugin::class.java) {
11778
extensions.configure(CommonExtension::class.java) {
11879
compileSdk = androidCompileSdkVersion
11980
ndkVersion = androidCompileNdkVersion
12081
buildToolsVersion = androidBuildToolsVersion
12182

83+
buildFeatures { buildConfig = true }
12284
externalNativeBuild {
12385
cmake {
12486
version = "3.29.8+"
@@ -128,10 +90,47 @@ subprojects {
12890

12991
defaultConfig {
13092
minSdk = androidMinSdkVersion
93+
ndk { abiFilters.addAll(listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64")) }
94+
13195
if (this is ApplicationDefaultConfig) {
13296
targetSdk = androidTargetSdkVersion
133-
versionCode = verCode
134-
versionName = verName
97+
98+
versionCode = versionCodeProvider.get().toInt()
99+
versionName = versionNameProvider.get()
100+
}
101+
102+
val flags =
103+
listOf(
104+
"-DVERSION_CODE=${versionCodeProvider.get()}",
105+
"-DVERSION_NAME='\"${versionNameProvider.get()}\"'",
106+
)
107+
108+
val args =
109+
listOf(
110+
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
111+
"-DVECTOR_ROOT=${rootDir.absolutePath}",
112+
)
113+
114+
externalNativeBuild {
115+
cmake {
116+
cFlags.addAll(flags)
117+
cppFlags.addAll(flags)
118+
arguments.addAll(args)
119+
}
120+
}
121+
}
122+
123+
buildTypes {
124+
getByName("release") {
125+
externalNativeBuild {
126+
cmake {
127+
arguments.add(
128+
"-DDEBUG_SYMBOLS_PATH=${
129+
layout.buildDirectory.dir("symbols").get().asFile.absolutePath
130+
}"
131+
)
132+
}
133+
}
135134
}
136135
}
137136

@@ -156,7 +155,12 @@ subprojects {
156155

157156
tasks.register<KtfmtFormatTask>("format") {
158157
source = project.fileTree(rootDir)
159-
include("*.gradle.kts", "*/build.gradle.kts")
158+
include(
159+
"*.gradle.kts",
160+
"*/build.gradle.kts",
161+
"hiddenapi/*/build.gradle.kts",
162+
"services/*-service/build.gradle.kts",
163+
)
160164
dependsOn(":xposed:ktfmtFormat")
161165
dependsOn(":zygisk:ktfmtFormat")
162166
}

core/build.gradle.kts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
1-
/*
2-
* This file is part of LSPosed.
3-
*
4-
* LSPosed is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* LSPosed is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
16-
*
17-
* Copyright (C) 2021 - 2022 LSPosed Contributors
18-
*/
1+
val versionCodeProvider: Provider<String> by rootProject.extra
2+
val versionNameProvider: Provider<String> by rootProject.extra
193

20-
val verName: String by rootProject.extra
21-
val verCode: Int by rootProject.extra
22-
23-
plugins {
24-
alias(libs.plugins.agp.lib)
25-
}
4+
plugins { alias(libs.plugins.agp.lib) }
265

276
android {
287
namespace = "org.lsposed.lspd.core"
298

30-
buildFeatures {
31-
androidResources = false
32-
buildConfig = true
33-
}
9+
androidResources { enable = false }
3410

3511
defaultConfig {
3612
consumerProguardFiles("proguard-rules.pro")
37-
3813
buildConfigField("String", "FRAMEWORK_NAME", """"${rootProject.name}"""")
39-
buildConfigField("String", "VERSION_NAME", """"$verName"""")
40-
buildConfigField("long", "VERSION_CODE", """$verCode""")
14+
buildConfigField("String", "VERSION_NAME", """"${versionCodeProvider.get()}"""")
15+
buildConfigField("long", "VERSION_CODE", versionCodeProvider.get())
4116
}
4217

4318
buildTypes {

core/src/main/java/org/lsposed/lspd/nativebridge/HookBridge.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

core/src/main/java/org/lsposed/lspd/nativebridge/NativeAPI.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

core/src/main/java/org/lsposed/lspd/nativebridge/ResourcesHook.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)