@@ -74,60 +74,6 @@ val downloadPowersyncDesktopBinaries by tasks.registering(Download::class) {
7474 onlyIfModified(true )
7575}
7676
77- val sqliteJDBCFolder =
78- project.layout.buildDirectory
79- .dir(" jdbc" )
80- .get()
81-
82- val jniLibsFolder = layout.projectDirectory.dir(" src/androidMain/jni" )
83-
84- val downloadJDBCJar by tasks.registering(Download ::class ) {
85- val version =
86- libs.versions.sqlite.jdbc
87- .get()
88- val jar =
89- " https://github.com/xerial/sqlite-jdbc/releases/download/$version /sqlite-jdbc-$version .jar"
90-
91- src(jar)
92- dest(sqliteJDBCFolder.file(" jdbc.jar" ))
93- onlyIfModified(true )
94- }
95-
96- val extractJDBCJNI by tasks.registering(Copy ::class ) {
97- dependsOn(downloadJDBCJar)
98-
99- from(
100- zipTree(downloadJDBCJar.get().dest).matching {
101- include(" org/sqlite/native/Linux-Android/**" )
102- },
103- )
104-
105- into(sqliteJDBCFolder.dir(" jni" ))
106- }
107-
108- val moveJDBCJNIFiles by tasks.registering(Copy ::class ) {
109- dependsOn(extractJDBCJNI)
110-
111- val abiMapping =
112- mapOf (
113- " aarch64" to " arm64-v8a" ,
114- " arm" to " armeabi-v7a" ,
115- " x86_64" to " x86_64" ,
116- " x86" to " x86" ,
117- )
118-
119- abiMapping.forEach { (sourceABI, androidABI) ->
120- from(sqliteJDBCFolder.dir(" jni/org/sqlite/native/Linux-Android/$sourceABI " )) {
121- include(" *.so" )
122- eachFile {
123- path = " $androidABI /$name "
124- }
125- }
126- }
127-
128- into(jniLibsFolder) // Move everything into the base jniLibs folder
129- }
130-
13177val generateVersionConstant by tasks.registering {
13278 val target = project.layout.buildDirectory.dir(" generated/constants" )
13379 val packageName = " com.powersync.build"
@@ -172,6 +118,12 @@ kotlin {
172118 headers(file(" src/watchosMain/powersync_static.h" ))
173119 }
174120 }
121+
122+ cinterops.create(" sqlite3" ) {
123+ packageName(" com.powersync.internal.sqlite3" )
124+ includeDirs.allHeaders(" src/nativeMain/interop/" )
125+ definitionFile.set(project.file(" src/nativeMain/interop/sqlite3.def" ))
126+ }
175127 }
176128 }
177129
@@ -183,6 +135,7 @@ kotlin {
183135 languageSettings {
184136 optIn(" kotlinx.cinterop.ExperimentalForeignApi" )
185137 optIn(" kotlin.time.ExperimentalTime" )
138+ optIn(" kotlin.experimental.ExperimentalObjCRefinement" )
186139 }
187140 }
188141
@@ -192,9 +145,6 @@ kotlin {
192145
193146 val commonJava by creating {
194147 dependsOn(commonMain.get())
195- dependencies {
196- implementation(libs.sqlite.jdbc)
197- }
198148 }
199149
200150 commonMain.configure {
@@ -203,6 +153,8 @@ kotlin {
203153 }
204154
205155 dependencies {
156+ api(libs.androidx.sqlite.sqlite)
157+
206158 implementation(libs.uuid)
207159 implementation(libs.kotlin.stdlib)
208160 implementation(libs.ktor.client.contentnegotiation)
@@ -212,29 +164,47 @@ kotlin {
212164 implementation(libs.kotlinx.datetime)
213165 implementation(libs.stately.concurrency)
214166 implementation(libs.configuration.annotations)
215- api(projects.persistence)
216167 api(libs.ktor.client.core)
217168 api(libs.kermit)
218169 }
219170 }
220171
221172 androidMain {
222173 dependsOn(commonJava)
223- dependencies.implementation(libs.ktor.client.okhttp)
174+ dependencies {
175+ implementation(libs.ktor.client.okhttp)
176+ implementation(libs.androidx.sqlite.bundled)
177+ }
224178 }
225179
226180 jvmMain {
227181 dependsOn(commonJava)
228182
229183 dependencies {
230184 implementation(libs.ktor.client.okhttp)
185+ implementation(libs.androidx.sqlite.bundled)
231186 }
232187 }
233188
234189 appleMain.dependencies {
235190 implementation(libs.ktor.client.darwin)
191+
192+ // We're not using the bundled SQLite library for Apple platforms. Instead, we depend on
193+ // static-sqlite-driver to link SQLite and have our own bindings implementing the
194+ // driver. The reason for this is that androidx.sqlite-bundled causes linker errors for
195+ // our Swift SDK.
196+ implementation(projects.staticSqliteDriver)
197+ }
198+
199+ // Common apple targets where we link the core extension dynamically
200+ val appleNonWatchOsMain by creating {
201+ dependsOn(appleMain.get())
236202 }
237203
204+ macosMain.orNull?.dependsOn(appleNonWatchOsMain)
205+ iosMain.orNull?.dependsOn(appleNonWatchOsMain)
206+ tvosMain.orNull?.dependsOn(appleNonWatchOsMain)
207+
238208 commonTest.dependencies {
239209 implementation(libs.kotlin.test)
240210 implementation(libs.test.coroutines)
@@ -294,12 +264,6 @@ android {
294264 ndkVersion = " 27.1.12297006"
295265}
296266
297- androidComponents.onVariants {
298- tasks.named(" preBuild" ) {
299- dependsOn(moveJDBCJNIFiles)
300- }
301- }
302-
303267tasks.named<ProcessResources >(kotlin.jvm().compilations[" main" ].processResourcesTaskName) {
304268 from(downloadPowersyncDesktopBinaries)
305269}
0 commit comments