问题描述
Kotlin和Java MainActivity类中的Android应用程序ID冲突
Android Application ID conflicts in Kotlin and Java MainActivity classes
错误:
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
Kotlin和Java MainActivity类均使用 flutter run
命令生成,并且都包含 package project.com.project
Both Kotlin and Java MainActivity classes are generated with the flutter run
command and both include package project.com.project
MainActivity.class
MainActivity.class
package project.com.project
public class MainActivity {
public MainActivity() {
}
}
MainActivity.kt
MainActivity.kt
package project.com.project
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
环境:
Android Studio 4.1.2
Gradle Plugin 4.1.2
Gradle Version 6.5
Flutter Version 1.22
在Android Studio中尝试过:
Tried in Android Studio :
Build -> Clean Project,
Build -> Rebuild Project,
File -> Invalidate Cache Restart
在命令行中尝试过
flutter clean
flutter run
rm -Rf ~/.gradle/caches
错误仍然存在.
推荐答案
我遇到了相同的错误,并且我的应用程序build.gradle具有以下依赖关系.
I got the same error and my app build.gradle had the following dependencies.
implementation 'com.google.android.material:material:1.2.1'
implementation "androidx.compose.ui:ui:$compose_version"
删除ui依赖关系后,它可以正常工作.原因是材料取决于ui.
After I remove the ui dependency, it works fine. The reason is that material depends on ui.
这篇关于多次定义了project.com.project.MainActivity类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!