diff --git a/CHANGELOG.md b/CHANGELOG.md index e002446e..a22a703e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Added `onChange` method to the PowerSync client. This allows for observing table changes. * Removed unnecessary `User-Id` header from internal PowerSync service requests. +* Fix loading native PowerSync extension for Java targets. ## 1.0.0-BETA31 diff --git a/core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt b/core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt index 9666b5ac..48c661be 100644 --- a/core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt +++ b/core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt @@ -1,6 +1,7 @@ package com.powersync import java.io.File +import java.util.UUID private class R @@ -21,14 +22,22 @@ internal fun extractLib(fileName: String): String { else -> error("Unsupported architecture: $sysArch") } - val path = "/$prefix${fileName}_$arch.$extension" + val suffix = UUID.randomUUID().toString() + val file = + File(System.getProperty("java.io.tmpdir"), "$prefix$fileName-$suffix.$extension").apply { + setReadable(true) + setWritable(true) + setExecutable(true) - val resourceURI = - (R::class.java.getResource(path) ?: error("Resource $path not found")) + deleteOnExit() + } + + val resourcePath = "/$prefix${fileName}_$arch.$extension" + + (R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $resourcePath not found")).use { input -> + file.outputStream().use { output -> input.copyTo(output) } + } - // Wrapping the above in a File handle resolves the URI to a path usable by SQLite. - // This is particularly relevant on Windows. - // On Windows [resourceURI.path] starts with a `/`, e.g. `/c:/...`. SQLite does not load this path correctly. - // The wrapping here transforms the path to `c:/...` which does load correctly. - return File(resourceURI.path).path.toString() + println("PowerSync loadable should be at $file") + return file.absolutePath } diff --git a/gradle.properties b/gradle.properties index f1a61d99..9056b618 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ development=true RELEASE_SIGNING_ENABLED=true # Library config GROUP=com.powersync -LIBRARY_VERSION=1.0.0-BETA31 +LIBRARY_VERSION=1.0.0-BETA32 GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git # POM POM_URL=https://github.com/powersync-ja/powersync-kotlin/