@@ -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+
94101val androidHome: String? = System .getenv(" ANDROID_HOME" )
95102 ? : System .getenv(" ANDROID_SDK_ROOT" )
96103
97104val isWindows = System .getProperty(" os.name" ).lowercase().contains(" win" )
105+ val isCI = System .getenv(" CI" ) == " true"
98106
99107val 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
103119val adbBin = androidHome?.let {
@@ -111,19 +127,26 @@ val classesJar =
111127val classesOutput = buildDir.resolve(" classes.dex" )
112128val 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