Skip to content

Fix extracting PowerSync library from JAR #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 17 additions & 8 deletions core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.powersync

import java.io.File
import java.util.UUID

private class R

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down