Skip to content

Commit deee4b1

Browse files
authored
Merge pull request #174 from powersync-ja/fix-loading-extension-from-jar
Fix extracting PowerSync library from JAR
2 parents 3ea01ff + 086881b commit deee4b1

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Added `onChange` method to the PowerSync client. This allows for observing table changes.
66
* Removed unnecessary `User-Id` header from internal PowerSync service requests.
7+
* Fix loading native PowerSync extension for Java targets.
78

89
## 1.0.0-BETA31
910

core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.powersync
22

33
import java.io.File
4+
import java.util.UUID
45

56
private class R
67

@@ -21,14 +22,22 @@ internal fun extractLib(fileName: String): String {
2122
else -> error("Unsupported architecture: $sysArch")
2223
}
2324

24-
val path = "/$prefix${fileName}_$arch.$extension"
25+
val suffix = UUID.randomUUID().toString()
26+
val file =
27+
File(System.getProperty("java.io.tmpdir"), "$prefix$fileName-$suffix.$extension").apply {
28+
setReadable(true)
29+
setWritable(true)
30+
setExecutable(true)
2531

26-
val resourceURI =
27-
(R::class.java.getResource(path) ?: error("Resource $path not found"))
32+
deleteOnExit()
33+
}
34+
35+
val resourcePath = "/$prefix${fileName}_$arch.$extension"
36+
37+
(R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $resourcePath not found")).use { input ->
38+
file.outputStream().use { output -> input.copyTo(output) }
39+
}
2840

29-
// Wrapping the above in a File handle resolves the URI to a path usable by SQLite.
30-
// This is particularly relevant on Windows.
31-
// On Windows [resourceURI.path] starts with a `/`, e.g. `/c:/...`. SQLite does not load this path correctly.
32-
// The wrapping here transforms the path to `c:/...` which does load correctly.
33-
return File(resourceURI.path).path.toString()
41+
println("PowerSync loadable should be at $file")
42+
return file.absolutePath
3443
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ development=true
1717
RELEASE_SIGNING_ENABLED=true
1818
# Library config
1919
GROUP=com.powersync
20-
LIBRARY_VERSION=1.0.0-BETA31
20+
LIBRARY_VERSION=1.0.0-BETA32
2121
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
2222
# POM
2323
POM_URL=https://github.com/powersync-ja/powersync-kotlin/

0 commit comments

Comments
 (0)