Trying to create a sample multiplatform library, which depends on a library (e.g. implementation(kotlinx.datetime)) in the commonMain. The library will expose a method (e.g. getDateTime), which will return an object (e.g. Instant). I did a test for it, it is working well within the library project. This library is eventually published to a local repository as an AAR file.
Below is the build config file for the library.
plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidLibrary) }
kotlin { targetHierarchy.default()
androidTarget { compilations.all { kotlinOptions { jvmTarget = "1.8" } } } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { it.binaries.framework { baseName = "dateTime" } } sourceSets { val commonMain by getting { dependencies { implementation(libs.kotlin.stdlib) } } val commonTest by getting { dependencies { implementation(libs.kotlin.test) } } } }
I created a normal kotlin Android app (that is not a multiplatform app) and successfully pulled the library into the app's dependency. In the main activity, it managed to access the getDateTime method. However, it is not able to resolve the return Object, which is an Instant object.
The compilations error message is saying
Cannot access class 'kotlinx.datetime.Instant'. Check your module classpath for missing or conflicting dependencies
Below is the extracted build config for the Android app.
dependencies {implementation("validation:datetime-android:1.0.0")}
Appreciate if someone can guide on how to resolve it, to enable the Android app to recognize the Instant Object, without manually including the kotlinx.datetime library in the normal Kotlin Android app's dependency.
Thanks for helping.