Unresolved reference: embedding and Unresolved reference: FlutterActivity in MainActivity.kt

Viewed 3329

My flutter app was working fine until days I go when it stopped building successfully

android/app/src/main/kotlin/com/apps/myapp/MainActivity.kt file

package com.apps.myapp

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
 
}

Console

Built build/app/outputs/repo.
Building plugin workmanager...
āœ“ Built build/app/outputs/repo.
e: /home/apps/myapp/android/app/src/main/kotlin/com/apps/myapp/MainActivity.kt: (3, 19): Unresolved reference: embedding
e: /home/apps/myapp/android/app/src/main/kotlin/com/apps/myapp/MainActivity.kt: (5, 21): Unresolved reference: FlutterActivity

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Help in fixing this issue please! thank you.

2 Answers

make sure you're on at least flutter 2.2.2. i had the same problem but i was able to fix it by:

  1. updating all my flutter plugins in pubspec.yaml
  2. updating flutter to 2.2.2
  3. try and avoid using plugins on the native sides (if not needed)
  4. compileSdkVersion 30 and targetSdkVersion 30
  5. ext.kotlin_version = '1.4.32'
  6. classpath 'com.android.tools.build:gradle:4.0.1'
  7. android.enableR8=true in your android/gradle.properties

I found solution on this. In my case the problems were being caused by location: ^1.4.1 package. I solved this issue by using an alternative package which is geolocator: ^5.1.1. I hope this helps someone too, good luck.

Related