Skip to content

Commit 77e8b5d

Browse files
committed
Refactor build tasks and update Gradle versions
Updated Gradle version references in libs.versions.toml and gradle-wrapper.properties. Refactored plugin/build.gradle.kts to improve task execution, add CI environment checks, and prevent ADB operations during CI runs. Enhanced code structure for d8 and adb task helpers.
1 parent 2cfdcf7 commit 77e8b5d

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
agp = "8.5.1"
3-
gradle = "8.1.4"
3+
gradle = "8.11.1"
44
platform = "v33773"
55
webuiXPortable = "v61"
66
ksp = "2.0.0-1.0.21"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Sun Apr 20 18:32:42 CEST 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

plugin/build.gradle.kts

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,30 @@ dependencies {
9090
ksp(libs.square.moshi.kotlin)
9191
}
9292

93-
// Optional D8 build task — unchanged
93+
interface InjectedExecOps {
94+
@get:Inject
95+
val execOps: ExecOperations
96+
}
97+
98+
val Task.injected get() = project.objects.newInstance<InjectedExecOps>()
99+
fun Task.exec(action: Action<in ExecSpec>): ExecResult = injected.execOps.exec(action)
100+
94101
val androidHome: String? = System.getenv("ANDROID_HOME")
95102
?: System.getenv("ANDROID_SDK_ROOT")
96103

97104
val isWindows = System.getProperty("os.name").lowercase().contains("win")
105+
val isCI = System.getenv("CI") == "true"
98106

99107
val d8Bin = androidHome?.let {
100-
File(it, "build-tools/${android.compileSdkVersion?.replace("android-", "")}.0.0/d8" + if (isWindows) ".bat" else "").absolutePath
108+
File(
109+
it,
110+
"build-tools/${
111+
android.compileSdkVersion?.replace(
112+
"android-",
113+
""
114+
)
115+
}.0.0/d8" + if (isWindows) ".bat" else ""
116+
).absolutePath
101117
}
102118

103119
val adbBin = androidHome?.let {
@@ -111,19 +127,26 @@ val classesJar =
111127
val classesOutput = buildDir.resolve("classes.dex")
112128
val dexOutput = buildDir.resolve("wxu.dex")
113129

114-
fun d8(vararg args: String) {
130+
fun Task.d8(vararg args: String) {
115131
if (d8Bin == null) {
116132
error("ANDROID_HOME or ANDROID_SDK_ROOT not set. Cannot locate d8.")
117133
}
134+
118135
exec {
119136
commandLine(d8Bin, *args)
120137
}
121138
}
122139

123-
fun adb(vararg args: String) {
140+
fun Task.adb(vararg args: String) {
141+
if (isCI) {
142+
print("ADB can't run in CI environment.")
143+
return
144+
}
145+
124146
if (adbBin == null) {
125147
error("ANDROID_HOME or ANDROID_SDK_ROOT not set. Cannot locate adb.")
126148
}
149+
127150
exec {
128151
commandLine(adbBin, *args)
129152
}
@@ -163,12 +186,15 @@ tasks.register("build-dex") {
163186

164187
if (classesOutput.renameTo(dexOutput)) {
165188
println("DEX file created at: $dexOutput")
166-
println("Pushing DEX file to device...")
167-
adb(
168-
"push",
169-
dexOutput.absolutePath,
170-
"/data/adb/modules/mmrl_wpd/webroot/plugins/wxu.dex"
171-
)
189+
190+
if (!isCI) {
191+
println("Pushing DEX file to device...")
192+
adb(
193+
"push",
194+
dexOutput.absolutePath,
195+
"/data/adb/modules/mmrl_wpd/webroot/plugins/wxu.dex"
196+
)
197+
}
172198
}
173199

174200
val latestSo = findLatestSoFile()
@@ -177,11 +203,14 @@ tasks.register("build-dex") {
177203
copyTo.parentFile.mkdirs()
178204
latestSo.copyTo(copyTo, overwrite = true)
179205
println("Copied .so to: $copyTo")
180-
adb(
181-
"push",
182-
latestSo.absolutePath,
183-
"/data/adb/modules/mmrl_wpd/webroot/shared/libnative.so"
184-
)
206+
207+
if (!isCI) {
208+
adb(
209+
"push",
210+
latestSo.absolutePath,
211+
"/data/adb/modules/mmrl_wpd/webroot/shared/libnative.so"
212+
)
213+
}
185214
} else {
186215
println("No .so file found in intermediates.")
187216
}

0 commit comments

Comments
 (0)