Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Kotlin cannot find FlutterActivity in MainActivity

ErrorUnresolved reference: FlutterActivity

Short 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.

  • Applies to Flutter 3.x, Android Gradle Plugin 8.x, Kotlin 2.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/java
  2. 2Match what you see, then jump to its fix

    1. 1The file contains import io.flutter.app.FlutterActivity, or MainActivity calls GeneratedPluginRegistrant.registerWith(this) inside onCreateMainActivity still imports the old v1 FlutterActivityFix
    2. 2Unresolved reference: FlutterEngine or GeneratedPluginRegistrant inside configureFlutterEngineCustom channel code uses FlutterEngine or GeneratedPluginRegistrant without importing themFix
    3. 3Unresolved reference: FlutterActivity in a native Android app that embeds a Flutter moduleAdd-to-app: the host app does not depend on the Flutter moduleFix

What does the error look like?

  • Unresolved reference: FlutterActivity
  • Unresolved reference: FlutterEngine
  • Unresolved 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/main

2Fix

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 --debug

Confirmed by github.com

Did this fix it?

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.kt

2Fix

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 --debug

Confirmed by github.com

Did this fix it?

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.kts

2Fix

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:assembleDebug

Confirmed by docs.flutter.dev

Did this fix it?

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:

Related fixes

Mobile 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.