Search code examples
flutterflutter-plugin

Stuck on step 2b in the Flutter Native Plugin guide


So I'm trying to get started with Flutter Plugin development, and I'm stuck on step 2b HERE.

Android Studio just shows the error:

Cannot Import Project
The project file specified already exists.

I'm pretty sure I've followed the instructions:

  1. flutter create --org com.example --template=plugin hello
  2. cd hello/example; flutter build apk

These steps all work fine, the example app seems to build, and then I get to step 2b, and Android Studio shows the error above.

flutter doctor:

[✓] Flutter (Channel dev, 1.20.0-1.0.pre, on Mac OS X 10.13.6 17G13035, locale en-DK)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.46.1)
[✓] Connected device (1 available)

Solution

  • It's easier to simply open the project, but be careful which folder to use.

    In Android Studio, in File>Open navigate to hello/example/android. This will open the example app. Once gradle has finished syncing you should see both the example app (which you won't change) and the plugin code (which you will) in the left panel.

    As you have VS Code installed, consider using that to edit the Dart code. (I can get confusing trying to use Android Studio for the Dart code as well as the Java/Kotlin code when developing a plugin.) In this case open the top level folder (hello). You'll want to make changes to hello/lib/hello.dart (the plugin API) and hello/example/lib/main.dart (the example Flutter app that exercises the API).