I have created a Flutter plugin project from Android Studio Koala. The project contains Java code which accesses various device dependent features such as the GPS, and bridges to the Dart code using the various Flutter methods – io.flutter.plugin.common.MethodCall, io.flutter.plugin.common.MethodChannel, io.flutter.plugin.common.EventChannel and various others. I’ve opened the Android project in a separate Android Studio window, as recommended in various places. However, all of the imports for these methods fail with the message “cannot resolve symbol flutter”. The Android Studio settings page shows that both the Flutter and Dart plugins are installed. There must be a simple solution to this – a missing entry in a config file or something – but I’ve been bashing my head against this problem for several hours and I can’t find a fix. Internet searches show that I’m not the only one who’s having this problem, but none of the proposed solutions which I’ve found have worked for me. Any ideas, anyone?
Well, I managed to solve the import problem by using the solution Android Studio: Add jar as library?.
Basically, I created a directory in my project, copied flutter.jar into this directory and added the jar file to build.gradle. However, when I ran the code, I got a large number of “duplicate entries” for the entry points in flutter.jar. So I removed the jar and ran the code with all of the io.flutter methods marked as unresolved – and hey presto, it worked.
So I now have code with loads of red in Android Studio, but which works. Very very irritating, both in the time lost trying to fix the non-existent problem and in having what looks like broken code, but isn’t.