icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.02k stars 95 forks source link

Installation problem - MutableLiveData points to wrong class in commonMain #73

Closed skokaina closed 3 years ago

skokaina commented 3 years ago

Hi,

Doing the following steps:

  1. installed Moko-MvvM, adding following dependencies in KMM shared sub-project:

    
    kotlin {
    android()
    val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }
    
    ....
    
    sourceSets["commonMain"].dependencies {
         ...
         api("dev.icerock.moko:mvvm:0.8.0")
    }
    
    sourceSets["androidMain"].dependencies {
        ...
        implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
        implementation("android.arch.lifecycle:extensions:2.2.0")
        implementation("androidx.lifecycle:lifecycle-extensions:2.2.0") 
    }

}


2. Updated LiveData and MutableLiveData in an existing ViewModel and ViewBinders (i.e using the .ld method to convert moko livedata to android live data)
3. Moved the ViewModel from the android app package to the KMM commonMain sub-module.

--- ISSUE

- Before moving the ViewModel to commonMain

<com.google.android.material.textfield.TextInputEditText ... android:text="@={viewModel.emailIdLiveData.ld()}" // <- works fine ... </com.google.android.material.textfield.TextInputLayout>


- After moving the ViewModel to commonMain

<com.google.android.material.textfield.TextInputEditText ... android:text="@={viewModel.emailIdLiveData.ld()}" // <- error - ld identifier not found ... </com.google.android.material.textfield.TextInputLayout>



Any clue or suggestion to solve this would be highly appreciated.
skokaina commented 3 years ago

Solved