1515 */
1616
1717
18+ import androidx.build.KmpPlatformsKt
1819import androidx.build.PlatformIdentifier
1920import androidx.build.Publish
21+ import androidx.build.SdkHelperKt
22+ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
23+ import org.jetbrains.kotlin.konan.target.KonanTarget
2024
2125plugins {
2226 id(" AndroidXPlugin" )
2327 id(" com.android.library" )
2428}
2529
30+ def nativeEnabled = KmpPlatformsKt . enableNative(project)
31+
32+ configurations {
33+ // Configuration for resolving shared archive file of androidx's SQLite compilation
34+ sqliteSharedArchive {
35+ canBeConsumed = false
36+ canBeResolved = true
37+ attributes {
38+ attribute(Usage . USAGE_ATTRIBUTE , objects. named(Usage , Usage . NATIVE_LINK ))
39+ }
40+ }
41+ }
42+
2643androidXMultiplatform {
2744 android()
2845 androidNative()
46+ ios() {
47+ // Link to sqlite3 available in iOS
48+ binaries. all {
49+ linkerOpts + = [" -lsqlite3" ]
50+ }
51+ }
2952 linux()
3053 mac()
31- ios()
3254
3355 defaultPlatform(PlatformIdentifier . ANDROID )
3456
3557 sourceSets {
3658 commonMain {
3759 dependencies {
3860 implementation(libs. kotlinStdlib)
61+ api(project(" :annotation:annotation" ))
3962 api(project(" :sqlite:sqlite" ))
4063 }
4164 }
4265 commonTest {
4366 dependencies {
67+ implementation(project(" :sqlite:integration-tests:driver-conformance-test" ))
4468 implementation(libs. kotlinTest)
4569 implementation(project(" :kruth:kruth" ))
4670 }
4771 }
4872 androidMain {
4973 dependsOn(commonMain)
50- dependencies {
51- api(" androidx.annotation:annotation:1.2.0" )
52- }
5374 }
5475 androidInstrumentedTest {
5576 dependsOn(commonTest)
@@ -59,17 +80,67 @@ androidXMultiplatform {
5980 implementation(libs. testCore)
6081 }
6182 }
83+ if (nativeEnabled) {
84+ nativeMain {
85+ dependsOn(commonMain)
86+ }
87+ nativeTest {
88+ dependsOn(commonTest)
89+ }
90+ }
91+ targets. all { target ->
92+ if (target. platformType == KotlinPlatformType . native ) {
93+ def main = target. compilations[" main" ]
94+ main. defaultSourceSet {
95+ dependsOn(nativeMain)
96+ }
97+ // For usage of C interop APIs
98+ // See: https://kotlinlang.org/docs/whatsnew19.html#explicit-c-interoperability-stability-guarantees
99+ main. compilerOptions. options. optIn. add(" kotlinx.cinterop.ExperimentalForeignApi" )
100+ main. cinterops {
101+ sqlite3 {
102+ def externalSQLiteDir = new File (
103+ SdkHelperKt . getCheckoutRoot(project),
104+ " /external/sqlite/dist/orig/"
105+ )
106+ includeDirs(externalSQLiteDir)
107+ }
108+ }
109+
110+ def test = target. compilations[" test" ]
111+ test. defaultSourceSet {
112+ dependsOn(nativeTest)
113+ }
114+ if (target. konanTarget == KonanTarget . LINUX_X64 . INSTANCE ) {
115+ // For tests in Linux host, statically include androidx's compiled SQLite
116+ // via a generated C interop definition
117+ createCinteropFromArchiveConfiguration(test, configurations[" sqliteSharedArchive" ])
118+ } else if (
119+ target. konanTarget == KonanTarget . MACOS_X64 . INSTANCE ||
120+ target. konanTarget == KonanTarget . MACOS_ARM64 . INSTANCE
121+ ) {
122+ // For tests in Mac host, link to shared SQLite library included in MacOS
123+ test. kotlinOptions. freeCompilerArgs + = [
124+ " -linker-options" , " -lsqlite3"
125+ ]
126+ }
127+ }
128+ }
62129 }
63130}
64131
132+ dependencies {
133+ sqliteSharedArchive(project(" :sqlite:sqlite-bundled" ))
134+ }
135+
65136androidx {
66137 name = " SQLite Framework Integration"
67138 publish = Publish . SNAPSHOT_AND_RELEASE
68139 inceptionYear = " 2017"
69- description = " The implementation of Support SQLite library using the framework code."
140+ description = " The implementation of SQLite library using the framework code."
70141 metalavaK2UastEnabled = true
71142}
72143
73144android {
74- namespace " androidx.sqlite.db.framework "
145+ namespace " androidx.sqlite.driver "
75146}
0 commit comments