KMP support for `lifecycle-runtime-testing`

* Converts `lifecycle-runtime-testing` to KMP.
* Libraries that require `lifecycle-runtime-testing` have been updated to use the latest `lifecycle` library, which includes KMP support.

RelNote: "`lifecycle-testing` is not KMP compatible."
Test: `:lifecycle:lifecycle-runtime-testing:desktopTest`
Change-Id: Iea41e975e31e22b3cf7a994c14e62454b9588b46
diff --git a/docs-tip-of-tree/build.gradle b/docs-tip-of-tree/build.gradle
index bb7a6a4..c2e4962 100644
--- a/docs-tip-of-tree/build.gradle
+++ b/docs-tip-of-tree/build.gradle
@@ -220,7 +220,7 @@
     kmpDocs(project(":lifecycle:lifecycle-runtime"))
     kmpDocs(project(":lifecycle:lifecycle-runtime-compose"))
     kmpDocs(project(":lifecycle:lifecycle-runtime-ktx"))
-    docs(project(":lifecycle:lifecycle-runtime-testing"))
+    kmpDocs(project(":lifecycle:lifecycle-runtime-testing"))
     docs(project(":lifecycle:lifecycle-service"))
     kmpDocs(project(":lifecycle:lifecycle-viewmodel"))
     kmpDocs(project(":lifecycle:lifecycle-viewmodel-compose"))
diff --git a/lifecycle/lifecycle-runtime-testing/bcv/native/current.txt b/lifecycle/lifecycle-runtime-testing/bcv/native/current.txt
new file mode 100644
index 0000000..85afe97
--- /dev/null
+++ b/lifecycle/lifecycle-runtime-testing/bcv/native/current.txt
@@ -0,0 +1,20 @@
+// Klib ABI Dump
+// Targets: [iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64]
+// Rendering settings:
+// - Signature version: 2
+// - Show manifest properties: true
+// - Show declarations: true
+
+// Library unique name: <androidx.lifecycle:lifecycle-runtime-testing>
+final class androidx.lifecycle.testing/TestLifecycleOwner : androidx.lifecycle/LifecycleOwner { // androidx.lifecycle.testing/TestLifecycleOwner|null[0]
+    constructor <init>(androidx.lifecycle/Lifecycle.State =..., kotlinx.coroutines/CoroutineDispatcher =...) // androidx.lifecycle.testing/TestLifecycleOwner.<init>|<init>(androidx.lifecycle.Lifecycle.State;kotlinx.coroutines.CoroutineDispatcher){}[0]
+    final fun handleLifecycleEvent(androidx.lifecycle/Lifecycle.Event) // androidx.lifecycle.testing/TestLifecycleOwner.handleLifecycleEvent|handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event){}[0]
+    final suspend fun setCurrentState(androidx.lifecycle/Lifecycle.State) // androidx.lifecycle.testing/TestLifecycleOwner.setCurrentState|setCurrentState(androidx.lifecycle.Lifecycle.State){}[0]
+    final val lifecycle // androidx.lifecycle.testing/TestLifecycleOwner.lifecycle|{}lifecycle[0]
+        final fun <get-lifecycle>(): androidx.lifecycle/LifecycleRegistry // androidx.lifecycle.testing/TestLifecycleOwner.lifecycle.<get-lifecycle>|<get-lifecycle>(){}[0]
+    final val observerCount // androidx.lifecycle.testing/TestLifecycleOwner.observerCount|{}observerCount[0]
+        final fun <get-observerCount>(): kotlin/Int // androidx.lifecycle.testing/TestLifecycleOwner.observerCount.<get-observerCount>|<get-observerCount>(){}[0]
+    final var currentState // androidx.lifecycle.testing/TestLifecycleOwner.currentState|{}currentState[0]
+        final fun <get-currentState>(): androidx.lifecycle/Lifecycle.State // androidx.lifecycle.testing/TestLifecycleOwner.currentState.<get-currentState>|<get-currentState>(){}[0]
+        final fun <set-currentState>(androidx.lifecycle/Lifecycle.State) // androidx.lifecycle.testing/TestLifecycleOwner.currentState.<set-currentState>|<set-currentState>(androidx.lifecycle.Lifecycle.State){}[0]
+}
diff --git a/lifecycle/lifecycle-runtime-testing/build.gradle b/lifecycle/lifecycle-runtime-testing/build.gradle
index 1025722..fb37804 100644
--- a/lifecycle/lifecycle-runtime-testing/build.gradle
+++ b/lifecycle/lifecycle-runtime-testing/build.gradle
@@ -21,29 +21,53 @@
  * 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.LibraryType
 
 plugins {
     id("AndroidXPlugin")
     id("com.android.library")
-    id("org.jetbrains.kotlin.android")
+}
+
+androidXMultiplatform {
+    android()
+    desktop()
+    mac()
+    linux()
+    ios()
+
+    defaultPlatform(PlatformIdentifier.ANDROID)
+
+    sourceSets {
+        commonMain {
+            dependencies {
+                api(libs.kotlinStdlib)
+                api(project(":lifecycle:lifecycle-runtime"))
+            }
+        }
+
+        commonTest {
+            dependencies {
+                implementation(libs.kotlinCoroutinesTest)
+                implementation(libs.kotlinTest)
+                implementation(project(":kruth:kruth"))
+            }
+        }
+
+        androidInstrumentedTest {
+            dependencies {
+                implementation(libs.truth)
+                implementation(libs.testExtJunit)
+                implementation(libs.testCore)
+                implementation(libs.testRunner)
+                implementation(libs.kotlinCoroutinesTest)
+            }
+        }
+    }
 }
 
 dependencies {
-    api(project(":lifecycle:lifecycle-runtime-ktx"))
-    api(libs.kotlinStdlib)
-    api(libs.kotlinCoroutinesAndroid)
-
-    testImplementation(libs.truth)
-    testImplementation(libs.junit)
-    testImplementation(libs.kotlinCoroutinesTest)
-
-    androidTestImplementation(libs.kotlinCoroutinesTest)
-    androidTestImplementation(libs.truth)
-    androidTestImplementation(libs.testExtJunit)
-    androidTestImplementation(libs.testCore)
-    androidTestImplementation(libs.testRunner)
-
     lintPublish(project(":lifecycle:lifecycle-runtime-testing-lint"))
 }
 
@@ -52,7 +76,6 @@
     type = LibraryType.PUBLISHED_LIBRARY
     inceptionYear = "2019"
     description = "Testing utilities for 'lifecycle' artifact"
-    metalavaK2UastEnabled = true
     legacyDisableKotlinStrictApiMode = true
 }
 
diff --git a/lifecycle/lifecycle-runtime-testing/src/androidTest/java/androidx/lifecycle/testing/TestLifecycleOwnerAndroidTest.kt b/lifecycle/lifecycle-runtime-testing/src/androidInstrumentedTest/kotlin/androidx/lifecycle/testing/TestLifecycleOwnerAndroidTest.kt
similarity index 100%
rename from lifecycle/lifecycle-runtime-testing/src/androidTest/java/androidx/lifecycle/testing/TestLifecycleOwnerAndroidTest.kt
rename to lifecycle/lifecycle-runtime-testing/src/androidInstrumentedTest/kotlin/androidx/lifecycle/testing/TestLifecycleOwnerAndroidTest.kt
diff --git a/lifecycle/lifecycle-runtime-testing/src/main/AndroidManifest.xml b/lifecycle/lifecycle-runtime-testing/src/androidMain/AndroidManifest.xml
similarity index 100%
rename from lifecycle/lifecycle-runtime-testing/src/main/AndroidManifest.xml
rename to lifecycle/lifecycle-runtime-testing/src/androidMain/AndroidManifest.xml
diff --git a/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt b/lifecycle/lifecycle-runtime-testing/src/commonMain/kotlin/androidx/lifecycle/testing/TestLifecycleOwner.kt
similarity index 97%
rename from lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
rename to lifecycle/lifecycle-runtime-testing/src/commonMain/kotlin/androidx/lifecycle/testing/TestLifecycleOwner.kt
index 5a23389..1a7b5f2 100644
--- a/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
+++ b/lifecycle/lifecycle-runtime-testing/src/commonMain/kotlin/androidx/lifecycle/testing/TestLifecycleOwner.kt
@@ -16,10 +16,10 @@
 
 package androidx.lifecycle.testing
 
-import android.annotation.SuppressLint
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleOwner
 import androidx.lifecycle.LifecycleRegistry
+import kotlin.jvm.JvmOverloads
 import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.runBlocking
@@ -44,7 +44,6 @@
     private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main.immediate
 ) : LifecycleOwner {
     // it is in test artifact
-    @SuppressLint("VisibleForTests")
     private val lifecycleRegistry =
         LifecycleRegistry.createUnsafe(this).apply { currentState = initialState }
 
diff --git a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleEventFlowTest.kt b/lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleEventFlowTest.kt
similarity index 94%
rename from lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleEventFlowTest.kt
rename to lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleEventFlowTest.kt
index dddbbab..c69fffe 100644
--- a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleEventFlowTest.kt
+++ b/lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleEventFlowTest.kt
@@ -16,9 +16,11 @@
 
 package androidx.lifecycle.testing
 
+import androidx.kruth.assertThat
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.eventFlow
-import com.google.common.truth.Truth.assertThat
+import kotlin.test.BeforeTest
+import kotlin.test.Test
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.launch
@@ -26,20 +28,15 @@
 import kotlinx.coroutines.test.UnconfinedTestDispatcher
 import kotlinx.coroutines.test.runTest
 import kotlinx.coroutines.test.setMain
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
 
 @OptIn(ExperimentalCoroutinesApi::class)
-@RunWith(JUnit4::class)
 class LifecycleEventFlowTest {
 
     private val dispatcher = UnconfinedTestDispatcher()
     private val owner = TestLifecycleOwner(coroutineDispatcher = dispatcher)
     private val testScope = TestScope(dispatcher)
 
-    @Before
+    @BeforeTest
     fun setMainDispatcher() {
         Dispatchers.setMain(dispatcher)
     }
diff --git a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt b/lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleRegistryTest.kt
similarity index 94%
rename from lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt
rename to lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleRegistryTest.kt
index 6b3e405..8ae88a8 100644
--- a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt
+++ b/lifecycle/lifecycle-runtime-testing/src/commonTest/kotlin/androidx/lifecycle/testing/LifecycleRegistryTest.kt
@@ -16,30 +16,28 @@
 
 package androidx.lifecycle.testing
 
+import androidx.kruth.assertThat
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleRegistry
-import com.google.common.truth.Truth.assertThat
+import kotlin.test.BeforeTest
+import kotlin.test.Test
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.test.TestScope
 import kotlinx.coroutines.test.UnconfinedTestDispatcher
 import kotlinx.coroutines.test.runTest
 import kotlinx.coroutines.test.setMain
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
 
-@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
-@RunWith(JUnit4::class)
+@OptIn(ExperimentalCoroutinesApi::class)
 class LifecycleRegistryTest {
 
     private val dispatcher = UnconfinedTestDispatcher()
     private val lifecycleOwner = TestLifecycleOwner(Lifecycle.State.INITIALIZED, dispatcher)
     private val testScope = TestScope(dispatcher)
 
-    @Before
+    @BeforeTest
     fun setMainDispatcher() {
         Dispatchers.setMain(dispatcher)
     }
diff --git a/paging/paging-runtime/build.gradle b/paging/paging-runtime/build.gradle
index 3561986..0d70131 100644
--- a/paging/paging-runtime/build.gradle
+++ b/paging/paging-runtime/build.gradle
@@ -38,9 +38,9 @@
     // Ensure that the -ktx dependency graph mirrors the Java dependency graph
     api(project(":paging:paging-common-ktx"))
 
-    api("androidx.lifecycle:lifecycle-livedata-ktx:2.4.0")
-    api("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0")
-    api("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0")
+    api("androidx.lifecycle:lifecycle-livedata-ktx:2.8.3")
+    api("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
+    api("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3")
     api("androidx.recyclerview:recyclerview:1.2.1")
     api(libs.kotlinStdlib)
     api(libs.kotlinCoroutinesAndroid)