add gradle task to download geode binaries

This commit is contained in:
Chloe committed 2026-07-31 18:17:06 -07:00
1 parent 758d5ad432
commit 269e85493b
4 files changed
+113 -1

No files matched your search

+102
View File
@@ -1,3 +1,6 @@
import java.net.URI
import java.util.zip.ZipInputStream
val composeBOM: String by rootProject.extra
kotlin {
@@ -12,6 +15,94 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose")
}
val currentGeodeVersion = "5.8.2"
abstract class DownloadAndUnzipGeodeTask : DefaultTask() {
@get:Input
abstract val geodeVersion: Property<String>
@get:Input
abstract val platform: Property<String>
@get:OutputFile
abstract val targetFile: RegularFileProperty
@TaskAction
fun execute() {
val downloadGeodeVersion = geodeVersion.get()
val downloadPlatform = platform.get()
val url = "https://github.com/geode-sdk/geode/releases/download/v$downloadGeodeVersion/geode-v$downloadGeodeVersion-$downloadPlatform.zip"
val destinationFile = targetFile.get().asFile
val expectedFile = "Geode.$downloadPlatform.so"
logger.info("Downloading Geode v$downloadGeodeVersion for platform $downloadPlatform")
ZipInputStream(URI.create(url).toURL().openStream()).use { zip ->
var entry = zip.nextEntry
while (entry != null) {
if (entry.name == expectedFile) {
destinationFile.outputStream().use {
zip.copyTo(it)
}
return@execute
}
entry = zip.nextEntry
}
throw GradleException("Could not find Geode release.")
}
}
}
val downloadGeode32Task = tasks.register<DownloadAndUnzipGeodeTask>("downloadGeode32Binary") {
description = "Downloads the 32bit Geode release archive"
inputs.property("geodeVersion", currentGeodeVersion)
geodeVersion = currentGeodeVersion
platform = "android32"
targetFile = temporaryDir.resolve("libgeode.so")
}
val downloadGeode64Task = tasks.register<DownloadAndUnzipGeodeTask>("downloadGeode64Binary") {
description = "Downloads the 64bit Geode release archive"
inputs.property("geodeVersion", currentGeodeVersion)
geodeVersion = currentGeodeVersion
platform = "android64"
targetFile = temporaryDir.resolve("libgeode.so")
}
abstract class MergeGeodeFilesTask : DefaultTask() {
@get:InputFile
abstract val binary32: RegularFileProperty
@get:InputFile
abstract val binary64: RegularFileProperty
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@TaskAction
fun execute() {
val out = outputDir.get().asFile
out.deleteRecursively()
out.mkdirs()
binary32.get().asFile.copyTo(outputDir.file("armeabi-v7a/libgeode.so").get().asFile)
binary64.get().asFile.copyTo(outputDir.file("arm64-v8a/libgeode.so").get().asFile)
}
}
val fullDownloadTask = tasks.register<MergeGeodeFilesTask>("downloadGeodeFull") {
description = "Downloads both Geode releases"
binary32 = downloadGeode32Task.flatMap { it.targetFile }
binary64 = downloadGeode64Task.flatMap { it.targetFile }
outputDir = layout.buildDirectory.dir("geode-prebuilt")
}
android {
compileSdk = 36
@@ -56,12 +147,14 @@ android {
dimension = "distribution"
isDefault = true
buildConfigField("boolean", "GOOGLE_PLAY_BUILD", "false")
buildConfigField("String", "PREBUNDLED_GEODE", "null")
}
create("googlePlay") {
dimension = "distribution"
applicationId = "com.geode.launcher.play"
buildConfigField("boolean", "GOOGLE_PLAY_BUILD", "true")
buildConfigField("String", "PREBUNDLED_GEODE", "\"$currentGeodeVersion\"")
}
}
@@ -102,6 +195,15 @@ android {
ndkVersion = "29.0.14206865"
}
androidComponents {
onVariants(selector().withFlavor("distribution" to "googlePlay")) { variant ->
variant.sources.jniLibs?.addGeneratedSourceDirectory(
fullDownloadTask,
MergeGeodeFilesTask::outputDir
)
}
}
dependencies {
implementation (platform("androidx.compose:compose-bom:$composeBOM"))
implementation ("androidx.core:core-ktx:1.18.0")
@@ -203,6 +203,7 @@ fun ErrorInfoDescription(description: String, modifier: Modifier = Modifier) {
val context = LocalContext.current
val currentRelease = remember {
PreferenceUtils.get(context).getString(PreferenceUtils.Key.CURRENT_VERSION_TAG)
?: BuildConfig.PREBUNDLED_GEODE
}
val gameVersion = remember {
@@ -665,7 +665,13 @@ fun AboutSettingsGroup(developerModeEnabled: Boolean) {
stringResource(R.string.preference_loader_version_name),
stringResource(
R.string.preference_loader_version_description,
currentRelease ?: "unknown"
currentRelease
?: "${BuildConfig.PREBUNDLED_GEODE}*"
.takeIf {
@Suppress("SENSELESS_COMPARISON")
BuildConfig.PREBUNDLED_GEODE != null
}
?: "unknown"
),
displayInline = true
)
@@ -42,6 +42,9 @@ object LaunchUtils {
}
fun isGeodeInstalled(context: Context): Boolean {
@Suppress("SENSELESS_COMPARISON")
if (BuildConfig.PREBUNDLED_GEODE != null) return true
return getInstalledGeodePath(context) != null
}