Reputation: 193
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
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
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
flutter clean
flutter pub get
flutter run
And then Invalidated the caches from the
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
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.
Upvotes: -1
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
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 = Your current Flutter project,2 = The android part of your flutter project]
GLHF :)
Upvotes: 35