Convert an existing Flutter Kotlin project to Flutter Java project. I had the same problem, for me this solution works.
1. Move folder com.example.test_app (any name you have) from android/app/src/main/kotlin -> android/app/src/main/java
2. Replace MainActivity.kt with Java version, or copy down here.
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.example.test_app; import android.os.Bundle; import io.flutter.app.FlutterActivity; import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GeneratedPluginRegistrant.registerWith(this); } } |
3. Remove following code android/app/build.grandle
1 2 3 4 5 6 | ... apply plugin: 'kotlin-android' ... sourceSets { main.java.srcDirs += 'src/main/kotlin' } |
4. In the same place replace following:
1 2 3 4 5 6 | dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.