Kotlin cannot find FlutterActivity in MainActivity
Unresolved reference: FlutterActivityShort answer
Kotlin only knows FlutterActivity if the import points at the v2 class, io.flutter.embedding.android.FlutterActivity, and the Flutter embedding is on the module's classpath. Check the import line first. In an add-to-app host, also confirm the Flutter module is included and added as a dependency. Custom channel code needs two more imports.
Fix it fast
1Find out which cause you have
Open MainActivity and read its import lines. The package in the import tells you which cause applies.
grep -rn "import io.flutter" android/app/src/main/kotlin android/app/src/main/java2Match what you see, then jump to its fix
- 1
The file contains import io.flutter.app.FlutterActivity, or MainActivity calls GeneratedPluginRegistrant.registerWith(this) inside onCreateMainActivity still imports the old v1 FlutterActivityFix - 2
Unresolved reference: FlutterEngine or GeneratedPluginRegistrant inside configureFlutterEngineCustom channel code uses FlutterEngine or GeneratedPluginRegistrant without importing themFix - 3
Unresolved reference: FlutterActivity in a native Android app that embeds a Flutter moduleAdd-to-app: the host app does not depend on the Flutter moduleFix
- 1
What does the error look like?
Unresolved reference: FlutterActivityUnresolved reference: FlutterEngineUnresolved reference: GeneratedPluginRegistrant
Cause 1 of 3
MainActivity still imports the old v1 FlutterActivity
1Check
io.flutter.app.FlutterActivity belongs to the v1 embedding, which an old project template used. Search for the old package name.
grep -rn "io.flutter.app" android/app/src/main2Fix
Import the v2 class and drop the manual plugin registration. The Flutter migration guide says the new FlutterActivity no longer needs plugins registered by hand.
package com.example.my_app
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity()3Verify
Build the app again. The unresolved reference is gone.
flutter build apk --debugConfirmed by github.com
Cause 2 of 3
Custom channel code uses FlutterEngine or GeneratedPluginRegistrant without importing them
1Check
If MainActivity overrides configureFlutterEngine, each class it uses needs its own import. Compare the file with the list in the migration guide.
sed -n '1,40p' android/app/src/main/kotlin/com/example/my_app/MainActivity.kt2Fix
Add the missing imports. Set up channels in configureFlutterEngine and register plugins with the engine, not from onCreate.
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}3Verify
Sync Gradle and rebuild.
flutter build apk --debugConfirmed by github.com
Cause 3 of 3
Add-to-app: the host app does not depend on the Flutter module
1Check
A native host only sees Flutter classes after settings.gradle includes the module and the app module depends on :flutter.
grep -n "include_flutter" settings.gradle.kts
grep -n "project(\":flutter\")" app/build.gradle.kts2Fix
Include the module in settings.gradle.kts and add the dependency in app/build.gradle.kts. Replace flutter_module with the name you gave flutter create.
// settings.gradle.kts
include(":app")
val filePath = settingsDir.parentFile.toString() + "/flutter_module/.android/include_flutter.groovy"
apply(from = File(filePath))
// app/build.gradle.kts
dependencies {
implementation(project(":flutter"))
}3Verify
Sync the project in Android Studio and build the host app.
./gradlew :app:assembleDebugConfirmed by docs.flutter.dev
How do I stop it coming back?
- Create Android code from the current flutter create template instead of copying a MainActivity from an old tutorial.
- Do not override onCreate only to call GeneratedPluginRegistrant; the v2 FlutterActivity handles it.
- In a host app, keep the include and the implementation(project(":flutter")) lines together in one commit.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
Related fixes
Mobile apps
Flutter build fails because the Android project uses the v1 embedding
Build failed due to use of deprecated Android v1 embedding
Your Android project was made before Flutter 1.12 and still uses the v1 embedding, while the plugins you use need v2.
3 causes, each with a fixMobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
Flutter Android build fails: module was compiled with an incompatible Kotlin version
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16
The compiler met a library built with a newer Kotlin than the one your project uses.
2 causes, each with a fixMobile apps
Flutter Android build says the project requires a newer Kotlin Gradle plugin
Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions
Flutter's Android build needs Kotlin Gradle plugin 1.5.31 or newer.
2 causes, each with a fixMobile apps
Play Console warns the bundle may be obfuscated and has no mapping file
This App Bundle contains Java/Kotlin code, which might be obfuscated.
This warning is about crash reports, not about your release being blocked.
3 causes, each with a fixMobile apps
Google Play says the app does not support 16 KB memory pages
check_elf_alignment.sh reports UNALIGNED for a library under lib/arm64-v8a
Google Play requires apps that target Android 15 or higher and ship native .so libraries to run on devices with 16 KB memory pages; from 1 February 2027 it will block updates that do not.
5 causes, each with a fix