Search code examples
android-studiokotlinkotlin-multiplatform

KMM how to import the generated Greeting class in my current project?


I've added a KMM module in my Android Studio project.

My project builds successfully.

Now to test everything I'm trying to use the auto-created Greeting class in my main project, but autocompletion does not suggests the class.

Am I missing something? Do I need to add something to my gradle file?

Thanks!


Solution

  • If you have just created a new project with KMM Application Template then you might have already got the simple example where Greeting is already imported in the project.

    Although if you are not able to import in any case then please check if you have added shared module in your dependencies of App level build.gradle.kts it looks like this :- implementation(project(":shared"))

    and then you need to import is as your shared package name.Greeting for example :- import com.example.kmmsample.shared.Greeting you can get your shared package name in manifest file for shared module it should be named as androidMain\AndroidManifest.xml

    Now in iOS you can simply add it as import shared if you have already added it in your Framework.