@@ -245,6 +245,32 @@ internal object PatchCommand : Runnable {
245
245
keyStoreFilePath ? : outputFilePath.parentFile
246
246
.resolve(" ${outputFilePath.nameWithoutExtension} .keystore" )
247
247
248
+ val installer = if (deviceSerial != null ) {
249
+ try {
250
+ if (mount) {
251
+ AdbRootInstaller (deviceSerial)
252
+ } else {
253
+ AdbInstaller (deviceSerial)
254
+ }
255
+ } catch (e: DeviceNotFoundException ) {
256
+ if (deviceSerial!! .isNotEmpty()) {
257
+ logger.severe(
258
+ " Device with serial $deviceSerial not found to install to. " +
259
+ " Ensure the device is connected and the serial is correct when using the --install option." ,
260
+ )
261
+ } else {
262
+ logger.severe(
263
+ " No device has been found to install to. " +
264
+ " Ensure a device is connected when using the --install option." ,
265
+ )
266
+ }
267
+
268
+ return
269
+ }
270
+ } else {
271
+ null
272
+ }
273
+
248
274
// endregion
249
275
250
276
// region Load patches
@@ -332,13 +358,7 @@ internal object PatchCommand : Runnable {
332
358
val deviceSerial = it.ifEmpty { null }
333
359
334
360
runBlocking {
335
- val result = if (mount) {
336
- AdbRootInstaller (deviceSerial)
337
- } else {
338
- AdbInstaller (deviceSerial)
339
- }.install(Installer .Apk (outputFilePath, packageName))
340
-
341
- when (result) {
361
+ when (val result = installer!! .install(Installer .Apk (outputFilePath, packageName))) {
342
362
RootInstallerResult .FAILURE -> logger.severe(" Failed to mount the patched APK file" )
343
363
is AdbInstallerResult .Failure -> logger.severe(result.exception.toString())
344
364
else -> logger.info(" Installed the patched APK file" )
0 commit comments