Converting existing Flutter Java Android project to Kotlin

Issue

I have an existing Flutter project that was created with Android Java set.
I tried removing my android directory and running flutter create -a kotlin .. App fails to run and error says it is still expecting main/java/com/myApp/MainActivity.java even though the main/kotlin/com/myApp/MainActivity.kt was generated. Any ideas?

Solution

In your android app level, check your build.gradle and make sure you have this

android {
    ...
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    ...
}

you can change the dir path to your MainActivity.kt placed

Answered By – cahyo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published