javaandroidflutterandroid-studiokotlin

Type project.com.project.MainActivity is defined multiple times


Android Application ID conflicts in Kotlin and Java MainActivity classes

Error:

Type project.com.project.MainActivity is defined multiple times 
./project/build/app/intermediates/javac/debug/classes/project/com/project/MainActivity.class,
./project/build/app/tmp/kotlin-classes/debug/project/com/project/MainActivity.class

Both Kotlin and Java MainActivity classes are generated with the flutter run command and both include package project.com.project

MainActivity.class

package project.com.project

public class MainActivity {
   public MainActivity() {
   }
}

MainActivity.kt

package project.com.project

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {

}

Environment :

Android Studio  4.1.2
Gradle Plugin       4.1.2 
Gradle Version  6.5 
Flutter Version     1.22

Tried in Android Studio :

Build -> Clean Project, 
Build -> Rebuild Project, 
File -> Invalidate Cache Restart 

Tried in Command Line :

flutter clean 
flutter run
rm -Rf ~/.gradle/caches 

The error is still there.


Solution

  • The conflict is caused by autogenerated Kotlin references in gradle.

    Removing all Kotlin entries from gradle config files is sufficient to get the flutter run command back to order