1+ import com.android.build.gradle.tasks.ExternalNativeBuildJsonTask
12import com.powersync.compile.CreateSqliteCInterop
23import com.powersync.plugins.utils.powersyncTargets
34import org.gradle.kotlin.dsl.register
@@ -35,6 +36,7 @@ fun linkSqlite3McCInterop(target: KotlinNativeTarget): TaskProvider<CreateSqlite
3536 val buildCInteropDef = tasks.register(" ${target.name} CinteropSqlite3Mc" , CreateSqliteCInterop ::class ) {
3637 val precompiledSqlite: FileCollection = nativeSqliteConfiguration
3738 inputs.files(precompiledSqlite)
39+ dependsOn(precompiledSqlite)
3840
3941 val staticLibrary = precompiledSqlite.singleFile.resolve(" ${target.konanTarget.name} sqlite3mc.a" )
4042 archiveFile.set(staticLibrary)
@@ -96,6 +98,11 @@ kotlin {
9698 }
9799}
98100
101+ val generateCmake by tasks.registering(Copy ::class ) {
102+ from(androidBuildSourceConfiguration)
103+ into(layout.buildDirectory.dir(" androidJniBuild" ))
104+ }
105+
99106android {
100107 compileOptions {
101108 targetCompatibility = JavaVersion .VERSION_17
@@ -116,7 +123,7 @@ android {
116123
117124 externalNativeBuild {
118125 cmake {
119- path(File (androidBuildSourceConfiguration.singleFile, " CMakeLists.txt" ) )
126+ path(" build/androidJniBuild/ CMakeLists.txt" )
120127 }
121128 }
122129
@@ -126,3 +133,10 @@ android {
126133tasks.named<ProcessResources >(kotlin.jvm().compilations[" main" ].processResourcesTaskName) {
127134 from(jniSqlite3McConfiguration)
128135}
136+
137+ tasks.withType(ExternalNativeBuildJsonTask ::class .java).configureEach {
138+ // Android runs these tasks to configure the CMake build. Since the CMake build in this case
139+ // is generated by a Gradle task (which copies artifacts around), we need to make sure that task
140+ // runs before CMake is invoked.
141+ dependsOn(generateCmake)
142+ }
0 commit comments