upstream: scrcpy v4 (#27)

* feat: download scrcpy-server in pre-build
* protocol alignment
* implement new options
* fix: switching after creating a new conf
* feat: implement `--new-display`
This commit is contained in:
謬紗特
2026-05-15 19:35:03 +08:00
committed by GitHub
parent 9e44788f84
commit a27d8638b4
18 changed files with 951 additions and 483 deletions

View File

@@ -1,3 +1,5 @@
import java.net.URI
import java.security.MessageDigest
import java.util.Properties
plugins {
@@ -56,8 +58,8 @@ android {
applicationId = "io.github.miuzarte.scrcpyforandroid"
minSdk = 26
targetSdk = 37
versionCode = 30
versionName = "0.3.4"
versionCode = 31
versionName = "0.4.0"
externalNativeBuild {
cmake {
@@ -162,3 +164,75 @@ dependencies {
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
}
val scrcpyServerAssetDir = "${project.projectDir}/src/main/assets/bin"
val scrcpyServerAssetFile = "$scrcpyServerAssetDir/scrcpy-server-v4.0"
val scrcpyServerDownloadUrl = "https://github.com/Genymobile/scrcpy/releases/download/v4.0/scrcpy-server-v4.0"
val scrcpyServerSha256 = "84924bd564a1eb6089c872c7521f968058977f91f5ff02514a8c74aff3210f3a"
val downloadScrcpyServer by tasks.registering {
description = "Download scrcpy-server binary from GitHub releases if absent or SHA256 mismatch"
group = "build setup"
inputs.property("downloadUrl", scrcpyServerDownloadUrl)
inputs.property("expectedSha256", scrcpyServerSha256)
outputs.file(scrcpyServerAssetFile)
doLast {
val file = outputs.files.singleFile
val url = inputs.properties["downloadUrl"] as String
val expectedSha = inputs.properties["expectedSha256"] as String
val dir = file.parentFile
if (!dir.exists()) dir.mkdirs()
fun computeSha256(f: File): String {
return f.inputStream().use { input ->
val digest = MessageDigest.getInstance("SHA-256")
val buffer = ByteArray(8192)
var count: Int
while (input.read(buffer).also { count = it } >= 0) {
digest.update(buffer, 0, count)
}
digest.digest().joinToString("") { "%02x".format(it) }
}
}
val needsDownload = !file.exists() || computeSha256(file) != expectedSha
if (needsDownload) {
logger.lifecycle("Downloading scrcpy-server-v4.0 from GitHub releases...")
try {
URI(url).toURL().openStream().use { input ->
file.outputStream().use { output ->
input.copyTo(output)
}
}
} catch (e: Exception) {
throw GradleException(
"Failed to download scrcpy-server-v4.0 from GitHub releases.\n" +
" URL: $url\n" +
" You may download it manually and place it at: ${file.absolutePath}\n" +
" If you are behind a proxy, check your Gradle proxy settings\n" +
" (gradle.properties: systemProp.https.proxyHost / systemProp.https.proxyPort).",
e
)
}
val actualSha = computeSha256(file)
require(actualSha == expectedSha) {
"SHA256 mismatch for scrcpy-server-v4.0!\n" +
" Expected: $expectedSha\n" +
" Got: $actualSha\n" +
" Delete ${file.absolutePath} to retry download."
}
logger.lifecycle("scrcpy-server-v4.0 downloaded and verified.")
} else {
logger.lifecycle("scrcpy-server-v4.0 exists with correct SHA256, skip download.")
}
}
}
tasks.named("preBuild") {
dependsOn(downloadScrcpyServer)
}