Talha Amin
Talha Amin

Reputation: 193

Flutter Cannot resolve symbol 'embedding' and Cannot resolve symbol 'FlutterActivity'

error shown in Flutter Android project folder in mainactivity

package com.malik.database_demo;

import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
}

Upvotes: 16

Views: 19808

Answers (5)

jilbot
jilbot

Reputation: 91

In my case this occurred after I updated the IntelliJ IDE. None of the above solutions worked, including opening in AS and rebuilding, invalidating caches, Flutter Clean, etc. The solution for me was to delete the android folder from the Flutter project and then re-add the Android platform as follows:

flutter create . --platforms=android

Upvotes: -1

Mamoon Shahzad
Mamoon Shahzad

Reputation: 63

What solved my problem is by navigating to the android part of the application as mentioned earlier in the first answer where the indexing of the gradle files was performed and then when I re opened the project view of the application then the error was still not resolved. Then I run the following commands

  1. flutter clean

  2. flutter pub get

  3. flutter run

And then Invalidated the caches from the

  • Menu>> File >>Invalidated caches

and finally restarted the Android Studio and boom the error was solved there were no errors. These were the steps that resolved my error.

Upvotes: 0

Dikascode
Dikascode

Reputation: 29

A little update on Servesh Dalvi's response: if you're using any of the latest versions of android studio like Android Studio Giraffe you might want to open your android part of your flutter project like the attached screenshot shows, by clicking on the android part directory, scroll down to Flutter, and select 'open Android module in Android Studio.Screenshot on opening android part of flutter project

Upvotes: -1

dbarton_uk
dbarton_uk

Reputation: 1067

I added flutter.jar as a library. This seemed to work.

I'm not sure if there are some unintended consequences yet!

Upvotes: 1

Sarvesh Dalvi
Sarvesh Dalvi

Reputation: 2678

Currently you are probably trying to directly edit the MainActivity class from your Flutter project. (By expanding android -> Navigation to 'MainActivity.java' or 'MainActivity.kt' and editing it).

I have observed that when we try to edit the native side code this way, Flutter is not able to recognize the android part.

What you can do is open the 'android' part of your flutter project and then edit it.

To achieve this :

  1. Click File -> Open -> Navigate to your current Flutter project -> Expand it and find the android part (refer the example below)

enter image description here

[1 = Your current Flutter project,2 = The android part of your flutter project]

  1. Click on that android part and click Open. Wait for the indexing and all to complete and then I dont think it will give those errors.

GLHF :)

Upvotes: 35

Related Questions