Make room-testing a KMP project

Also removed the single AutoMigration test in the project as that is already covered by multiple other tests in the integration test projects. By removing the test we avoid applying KSP to the project and thus saving a bit of build time. Infra will be happy... :)

Bug: 299168035
Test: ./gradlew :room:room-testing:build
Change-Id: I953908b1227b83df859a2c305ecc7e5481b558ae
diff --git a/docs-tip-of-tree/build.gradle b/docs-tip-of-tree/build.gradle
index ea1a9dd..e9596b8 100644
--- a/docs-tip-of-tree/build.gradle
+++ b/docs-tip-of-tree/build.gradle
@@ -333,7 +333,7 @@
     kmpDocs(project(":room:room-runtime"))
     docs(project(":room:room-rxjava2"))
     docs(project(":room:room-rxjava3"))
-    docs(project(":room:room-testing"))
+    kmpDocs(project(":room:room-testing"))
     docs(project(":safeparcel:safeparcel"))
     docs(project(":savedstate:savedstate"))
     docs(project(":savedstate:savedstate-ktx"))
diff --git a/room/room-testing/build.gradle b/room/room-testing/build.gradle
index 8fbdb36..037fbc6 100644
--- a/room/room-testing/build.gradle
+++ b/room/room-testing/build.gradle
@@ -21,44 +21,67 @@
  * Please use that script when creating a new project, rather than copying an existing project and
  * modifying its settings.
  */
+
+import androidx.build.PlatformIdentifier
 import androidx.build.Publish
+import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
 
 plugins {
     id("AndroidXPlugin")
     id("com.android.library")
-    id("kotlin-android")
-    id("com.google.devtools.ksp")
+}
+
+androidXMultiplatform {
+    android()
+    ios()
+    jvm()
+    linux()
+    mac()
+
+    defaultPlatform(PlatformIdentifier.ANDROID)
+
+    sourceSets {
+        commonMain {
+            dependencies {
+                api(libs.kotlinStdlib)
+                api(project(":room:room-common"))
+                api(project(":room:room-runtime"))
+                api(project(":room:room-migration"))
+                api(project(":sqlite:sqlite"))
+            }
+        }
+        commonTest {
+            dependencies {
+                implementation(libs.kotlinTest)
+                implementation(project(":kruth:kruth"))
+            }
+        }
+        jvmMain {
+            dependsOn(commonMain)
+        }
+        androidMain {
+            dependsOn(commonMain)
+            dependencies {
+                api(libs.junit)
+                api(project(":sqlite:sqlite-framework"))
+                implementation("androidx.arch.core:core-runtime:2.2.0")
+            }
+        }
+        nativeMain {
+            dependsOn(commonMain)
+        }
+        targets.all { target ->
+            if (target.platformType == KotlinPlatformType.native) {
+                target.compilations["main"].defaultSourceSet {
+                    dependsOn(nativeMain)
+                }
+            }
+        }
+    }
 }
 
 android {
     namespace "androidx.room.testing"
-    sourceSets {
-        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
-    }
-}
-
-dependencies {
-    api(project(":room:room-common"))
-    api(project(":room:room-runtime"))
-    api(project(":sqlite:sqlite"))
-    api(project(":sqlite:sqlite-framework"))
-    api(project(":room:room-migration"))
-    api(libs.junit)
-    implementation("androidx.arch.core:core-runtime:2.2.0")
-    androidTestImplementation(libs.truth) // Kruth currently lacks StringSubject#containsMatch
-    androidTestImplementation(project(":kruth:kruth"))
-    androidTestImplementation(libs.kotlinStdlib)
-    androidTestImplementation(libs.testExtJunit)
-    androidTestImplementation(libs.testCore)
-    androidTestImplementation(libs.testRunner)
-    androidTestImplementation(libs.espressoCore)
-    kspAndroidTest(
-            project(path: ":room:room-compiler", configuration: "shadowAndImplementation")
-    )
-}
-
-ksp {
-    arg("room.schemaLocation", "$projectDir/schemas".toString())
 }
 
 androidx {
diff --git a/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/1.json b/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/1.json
deleted file mode 100644
index a38401f..0000000
--- a/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/1.json
+++ /dev/null
@@ -1,87 +0,0 @@
-{
-  "formatVersion": 1,
-  "database": {
-    "version": 1,
-    "identityHash": "6ffabe84cb2c6c45dbb6d478ab3cb00e",
-    "entities": [
-      {
-        "tableName": "Entity1",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `addedInV1` INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`id`))",
-        "fields": [
-          {
-            "fieldPath": "id",
-            "columnName": "id",
-            "affinity": "INTEGER",
-            "notNull": true
-          },
-          {
-            "fieldPath": "name",
-            "columnName": "name",
-            "affinity": "TEXT",
-            "notNull": true
-          },
-          {
-            "fieldPath": "addedInV1",
-            "columnName": "addedInV1",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "1"
-          }
-        ],
-        "primaryKey": {
-          "autoGenerate": false,
-          "columnNames": [
-            "id"
-          ]
-        },
-        "indices": [],
-        "foreignKeys": []
-      },
-      {
-        "tableName": "Entity2",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `addedInV1` INTEGER NOT NULL DEFAULT 1, `addedInV2` INTEGER NOT NULL DEFAULT 2, PRIMARY KEY(`id`))",
-        "fields": [
-          {
-            "fieldPath": "id",
-            "columnName": "id",
-            "affinity": "INTEGER",
-            "notNull": true
-          },
-          {
-            "fieldPath": "name",
-            "columnName": "name",
-            "affinity": "TEXT",
-            "notNull": true
-          },
-          {
-            "fieldPath": "addedInV1",
-            "columnName": "addedInV1",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "1"
-          },
-          {
-            "fieldPath": "addedInV2",
-            "columnName": "addedInV2",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "2"
-          }
-        ],
-        "primaryKey": {
-          "autoGenerate": false,
-          "columnNames": [
-            "id"
-          ]
-        },
-        "indices": [],
-        "foreignKeys": []
-      }
-    ],
-    "views": [],
-    "setupQueries": [
-      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
-      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6ffabe84cb2c6c45dbb6d478ab3cb00e')"
-    ]
-  }
-}
\ No newline at end of file
diff --git a/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/2.json b/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/2.json
deleted file mode 100644
index 052b6f5..0000000
--- a/room/room-testing/schemas/androidx.room.testing.kotlintestapp.migration.SimpleAutoMigrationDb/2.json
+++ /dev/null
@@ -1,87 +0,0 @@
-{
-  "formatVersion": 1,
-  "database": {
-    "version": 2,
-    "identityHash": "e6ac760b64fa91da605ebdfefc93c88e",
-    "entities": [
-      {
-        "tableName": "Entity1",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT, `addedInV1` INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`id`))",
-        "fields": [
-          {
-            "fieldPath": "id",
-            "columnName": "id",
-            "affinity": "INTEGER",
-            "notNull": true
-          },
-          {
-            "fieldPath": "name",
-            "columnName": "name",
-            "affinity": "TEXT",
-            "notNull": false
-          },
-          {
-            "fieldPath": "addedInV1",
-            "columnName": "addedInV1",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "1"
-          }
-        ],
-        "primaryKey": {
-          "columnNames": [
-            "id"
-          ],
-          "autoGenerate": false
-        },
-        "indices": [],
-        "foreignKeys": []
-      },
-      {
-        "tableName": "Entity2",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT, `addedInV1` INTEGER NOT NULL DEFAULT 1, `addedInV2` INTEGER NOT NULL DEFAULT 2, PRIMARY KEY(`id`))",
-        "fields": [
-          {
-            "fieldPath": "id",
-            "columnName": "id",
-            "affinity": "INTEGER",
-            "notNull": true
-          },
-          {
-            "fieldPath": "name",
-            "columnName": "name",
-            "affinity": "TEXT",
-            "notNull": false
-          },
-          {
-            "fieldPath": "addedInV1",
-            "columnName": "addedInV1",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "1"
-          },
-          {
-            "fieldPath": "addedInV2",
-            "columnName": "addedInV2",
-            "affinity": "INTEGER",
-            "notNull": true,
-            "defaultValue": "2"
-          }
-        ],
-        "primaryKey": {
-          "columnNames": [
-            "id"
-          ],
-          "autoGenerate": false
-        },
-        "indices": [],
-        "foreignKeys": []
-      }
-    ],
-    "views": [],
-    "setupQueries": [
-      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
-      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'e6ac760b64fa91da605ebdfefc93c88e')"
-    ]
-  }
-}
\ No newline at end of file
diff --git a/room/room-testing/src/main/java/androidx/room/testing/BundleUtil.kt b/room/room-testing/src/androidMain/kotlin/androidx/room/testing/BundleUtil.android.kt
similarity index 100%
rename from room/room-testing/src/main/java/androidx/room/testing/BundleUtil.kt
rename to room/room-testing/src/androidMain/kotlin/androidx/room/testing/BundleUtil.android.kt
diff --git a/room/room-testing/src/main/java/androidx/room/testing/MigrationTestHelper.kt b/room/room-testing/src/androidMain/kotlin/androidx/room/testing/MigrationTestHelper.android.kt
similarity index 100%
rename from room/room-testing/src/main/java/androidx/room/testing/MigrationTestHelper.kt
rename to room/room-testing/src/androidMain/kotlin/androidx/room/testing/MigrationTestHelper.android.kt
diff --git a/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/AutoMigrationAndMigrationTest.kt b/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/AutoMigrationAndMigrationTest.kt
deleted file mode 100644
index 7269905..0000000
--- a/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/AutoMigrationAndMigrationTest.kt
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.room.testing.kotlintestapp.migration
-
-import android.database.sqlite.SQLiteException
-import androidx.kruth.assertThat
-import androidx.room.migration.Migration
-import androidx.room.testing.MigrationTestHelper
-import androidx.sqlite.db.SupportSQLiteDatabase
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.LargeTest
-import androidx.test.platform.app.InstrumentationRegistry
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-
-/**
- * Test custom database migrations.
- */
-@RunWith(AndroidJUnit4::class)
-@LargeTest
-class AutoMigrationAndMigrationTest {
-    @JvmField
-    @Rule
-    var helper: MigrationTestHelper = MigrationTestHelper(
-        InstrumentationRegistry.getInstrumentation(),
-        SimpleAutoMigrationDb::class.java
-    )
-
-    // Run this to create the very 1st version of the db.
-    fun createFirstVersion() {
-        val db = helper.createDatabase(TEST_DB, 1)
-        db.execSQL("INSERT INTO Entity1 (id, name) VALUES (1, 'row1')")
-        db.execSQL("INSERT INTO Entity2 (id, name) VALUES (2, 'row2')")
-        db.close()
-    }
-
-    /**
-     * Verifies that the user defined migration is selected over using an autoMigration.
-     */
-    @Test
-    fun testAutoMigrationsNotProcessedBeforeCustomMigrations() {
-        createFirstVersion()
-        try {
-            helper.runMigrationsAndValidate(
-                TEST_DB,
-                2,
-                true,
-                MIGRATION_1_2
-            )
-        } catch (e: SQLiteException) {
-            assertThat(e.message).contains("no such table: Entity0")
-        }
-    }
-
-    @Test
-    fun autoMigrationShouldBeAddedToMigrations_WhenManualDowngradeMigrationIsPresent() {
-        createFirstVersion()
-        helper.runMigrationsAndValidate(
-            TEST_DB,
-            2,
-            true,
-            MIGRATION_1_0
-        )
-        val config = helper.databaseConfiguration
-        assertThat(config).isNotNull()
-        assertThat(config.migrationContainer.findMigrationPath(1, 2)).isNotNull()
-        assertThat(config.migrationContainer.findMigrationPath(1, 2)).isNotEmpty()
-    }
-
-    companion object {
-        private const val TEST_DB = "auto-migration-test"
-        private val MIGRATION_1_2: Migration = object : Migration(1, 2) {
-            override fun migrate(db: SupportSQLiteDatabase) {
-                db.execSQL(
-                    "ALTER TABLE `Entity0` ADD COLUMN `addedInV2` INTEGER NOT NULL " +
-                        "DEFAULT 2"
-                )
-            }
-        }
-        private val MIGRATION_1_0: Migration = object : Migration(1, 0) {
-            override fun migrate(db: SupportSQLiteDatabase) {}
-        }
-    }
-}
diff --git a/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/SimpleAutoMigrationDb.kt b/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/SimpleAutoMigrationDb.kt
deleted file mode 100644
index da1c645..0000000
--- a/room/room-testing/src/androidTest/java/androidx/room/testing/kotlintestapp/migration/SimpleAutoMigrationDb.kt
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.room.testing.kotlintestapp.migration
-
-import androidx.room.AutoMigration
-import androidx.room.ColumnInfo
-import androidx.room.Dao
-import androidx.room.Database
-import androidx.room.Entity
-import androidx.room.PrimaryKey
-import androidx.room.Query
-import androidx.room.RoomDatabase
-import androidx.room.migration.AutoMigrationSpec
-import androidx.sqlite.db.SupportSQLiteDatabase
-
-@Database(
-    version = SimpleAutoMigrationDb.LATEST_VERSION,
-    entities = [
-        SimpleAutoMigrationDb.Entity1::class,
-        SimpleAutoMigrationDb.Entity2::class],
-    autoMigrations = [AutoMigration(
-        from = 1,
-        to = 2,
-        spec = SimpleAutoMigrationDb.SimpleAutoMigration1::class
-    )],
-    exportSchema = true
-)
-abstract class SimpleAutoMigrationDb : RoomDatabase() {
-    internal abstract fun dao(): AutoMigrationDao
-
-    /**
-     * No change between versions.
-     */
-    @Entity
-    data class Entity1(
-        @PrimaryKey
-        var id: Int,
-        var name: String,
-        @ColumnInfo(defaultValue = "1")
-        var addedInV1: Int,
-    ) {
-
-        companion object {
-            const val TABLE_NAME = "Entity1"
-        }
-    }
-
-    /**
-     * A new simple column added to Entity 2 with a default value.
-     */
-    @Entity
-    data class Entity2(
-        @PrimaryKey
-        var id: Int,
-        var name: String,
-
-        @ColumnInfo(defaultValue = "1")
-        var addedInV1: Int,
-
-        @ColumnInfo(defaultValue = "2")
-        var addedInV2: Int
-    ) {
-        companion object {
-            const val TABLE_NAME = "Entity2"
-        }
-    }
-
-    @Dao
-    internal interface AutoMigrationDao {
-        @Query("SELECT * from Entity1 ORDER BY id ASC")
-        fun getAllEntity1s(): List<Entity1>
-    }
-
-    internal class SimpleAutoMigration1 : AutoMigrationSpec {
-        override fun onPostMigrate(db: SupportSQLiteDatabase) {
-            // Do something
-        }
-    }
-
-    companion object {
-        const val LATEST_VERSION = 1
-    }
-}
diff --git a/room/room-testing/src/commonMain/kotlin/androidx/room/testing/Placeholder.kt b/room/room-testing/src/commonMain/kotlin/androidx/room/testing/Placeholder.kt
new file mode 100644
index 0000000..3e91597
--- /dev/null
+++ b/room/room-testing/src/commonMain/kotlin/androidx/room/testing/Placeholder.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.room.testing
+// empty file to trigger klib creation
+// see: https://youtrack.jetbrains.com/issue/KT-52344
diff --git a/room/room-testing/src/main/AndroidManifest.xml b/room/room-testing/src/main/AndroidManifest.xml
deleted file mode 100644
index da23b80..0000000
--- a/room/room-testing/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<!--
-  ~ Copyright (C) 2017 The Android Open Source Project
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License.
-  -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
-</manifest>
diff --git a/settings.gradle b/settings.gradle
index fe302a7..9058003 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -909,7 +909,7 @@
 includeProject(":room:room-runtime-lint", [BuildType.MAIN, BuildType.COMPOSE])
 includeProject(":room:room-rxjava2", [BuildType.MAIN])
 includeProject(":room:room-rxjava3", [BuildType.MAIN])
-includeProject(":room:room-testing", [BuildType.MAIN])
+includeProject(":room:room-testing", [BuildType.MAIN, BuildType.KMP, BuildType.INFRAROGUE])
 includeProject(":safeparcel:safeparcel", [BuildType.MAIN])
 includeProject(":safeparcel:safeparcel-processor", [BuildType.MAIN])
 includeProject(":savedstate:savedstate", [BuildType.MAIN, BuildType.COMPOSE, BuildType.FLAN])