66 lines
2.1 KiB
Kotlin
66 lines
2.1 KiB
Kotlin
package com.lagradost.cloudstream3.gradle.tasks
|
|
|
|
import com.lagradost.cloudstream3.gradle.getCloudstream
|
|
import com.android.build.gradle.BaseExtension
|
|
import org.gradle.api.DefaultTask
|
|
import org.gradle.api.tasks.AbstractCopyTask
|
|
import org.gradle.api.tasks.Input
|
|
import org.gradle.api.tasks.TaskAction
|
|
import org.gradle.api.tasks.options.Option
|
|
import se.vidstige.jadb.*
|
|
import java.nio.charset.StandardCharsets
|
|
|
|
abstract class DeployWithAdbTask : DefaultTask() {
|
|
@get:Input
|
|
@set:Option(option = "wait-for-debugger", description = "Enables debugging flag when starting the discord activity")
|
|
var waitForDebugger: Boolean = false
|
|
|
|
@TaskAction
|
|
fun deployWithAdb() {
|
|
val extension = project.extensions.getCloudstream()
|
|
val android = project.extensions.getByName("android") as BaseExtension
|
|
|
|
AdbServerLauncher(Subprocess(), android.adbExecutable.absolutePath).launch()
|
|
val jadbConnection = JadbConnection()
|
|
val devices = jadbConnection.devices.filter {
|
|
try {
|
|
it.state == JadbDevice.State.Device
|
|
} catch (e: JadbException) {
|
|
false
|
|
}
|
|
}
|
|
|
|
require(devices.size == 1) {
|
|
"Only one ADB device should be connected, but ${devices.size} were!"
|
|
}
|
|
|
|
val device = devices[0]
|
|
|
|
val make = project.tasks.getByName("make") as AbstractCopyTask
|
|
|
|
var file = make.outputs.files.singleFile
|
|
|
|
|
|
var path = "/storage/emulated/0/Cloudstream3/plugins/"
|
|
|
|
device.push(file, RemoteFile(path + file.name))
|
|
|
|
if (extension.projectType.get() != ProjectType.INJECTOR) {
|
|
val args = arrayListOf("start", "-S", "-n", "com.lagradost.cloudstream3.debug/com.lagradost.cloudstream3.MainActivity")
|
|
|
|
if (waitForDebugger) {
|
|
args.add("-D")
|
|
}
|
|
|
|
val response = String(
|
|
device.executeShell("am", *args.toTypedArray()).readAllBytes(), StandardCharsets.UTF_8
|
|
)
|
|
|
|
if (response.contains("Error")) {
|
|
logger.error(response)
|
|
}
|
|
}
|
|
|
|
logger.lifecycle("Deployed $file to ${device.serial}")
|
|
}
|
|
} |