Leonardo da Silva
Leonardo da Silva

Reputation: 1495

Flutter not found when developing plugin for Android

I forked a plugin with the intent to make an update to use the embedding v2 for Android. But when I opened the android folder on Android Studio it does not find Flutter. It fails to import these classes:

import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.PluginRegistry.Registrar;

Is there anything I am missing to edit the Android part of a Flutter plugin?

This is the plugin I am trying to update: https://github.com/lslv1243/launch_review

Thanks in advance!

Upvotes: 27

Views: 17575

Answers (7)

Dominic
Dominic

Reputation: 715

After days of trying to resolve this issue, what fixed it for me was: https://github.com/flutter/flutter/issues/19830#issuecomment-1688736003

It turns out, you have to build the android app first in the example directory.

  1. Call flutter build apk --config-only in the <your_plugin>/example/android. (Take note of the example directory).
  2. Finally, open the <your_plugin>/example/android in Android Studio (Still in the example directory).

It should open two Android modules:<your_plugin>/example/android and <your_plugin>/android.

Upvotes: 2

BattleCall
BattleCall

Reputation: 31

Depends on a flutter plugin project. (my as version is Android Studio Electric Eel | 2022.1.1 Patch 2)

like this flutter create --org com.example --template=plugin plugin_himan --platforms=ios,android,linux,windows,macos --android-language=java --ios-language=objc

  • in android studio, open Project Structure

  • Select Project Settings-Modules, then you can see plugin_himan and plugin_himan_android

  • select Dependencies, Module SDK chose one you need

  • click + button, chose Jars or Directories (copy your flutter_embedding_debug.jar path)

Now you can direct use flutter package or class, in plugin_himain/android project. How to get flutter_embedding_debug.jar.

  1. build flutter engine source
  2. or use gradle like this compileOnly io.flutter:flutter_embedding_debug:1.0.0-tag, in download get ETag replace tag in io.flutter:flutter_embedding_debug:1.0.0-tag

Upvotes: 1

Lins Louis
Lins Louis

Reputation: 2633

I faced a similar situation when I imported an android project from the plug-in module of my Flutter project. That means, My Flutter project has an android folder at the root directory of the project, and another android directory inside the module I imported as a plug-in. If I try to open that module with the android studio it will not detect "io.flutter.plugin.common" packages.Because it missing the 'flutter.jar' library.

So what I did was, I Just added the flutter.jar path to dependency,

implementation files('/Users/username/Developer/flutter/bin/cache/artifacts/engine/android-arm64-release/flutter.jar')

here I choose 'android-arm64-release' because I am using M1 chip macbook.

Now i can edit the android module of the plugin project.But to run the flutter project i have to comment out the flutter.jar dependency and sync again before run, otherwise it will show conflict errors.

Upvotes: 10

Georgii
Georgii

Reputation: 472

It turned out to be a known error: https://github.com/flutter/flutter/issues/19830. You can find different solutions and general discussion of the problem there.

Provided solutions did not help in my case. What had worked out is this one (by @incloudss):

For everyone who still struggles with that problem, ignore the official documentation, and do not open android project the way they describe it there.

Instead:

  1. Open the main flutter project.
  2. Go to Tools -> Flutter -> Open For Editing In Android Studio(yes, it doesn't >make sense because we are already in AS, but it works).

Upvotes: 9

nyarian
nyarian

Reputation: 4365

It worked for me when I did the next steps (assuming that Dart and Flutter plugins are configured in the Android Studio Preferences properly):

  1. Close all the projects up until you see the "welcome to Android Studio" window with recent projects list and a set of options in the center
  2. Select "Open existing Android Studio project"
  3. Select the file plugin/example/android/build.gradle

Upvotes: 23

Kapandaria
Kapandaria

Reputation: 593

You should open the project in android studio from the example/android location.

Upvotes: 11

Code Poet
Code Poet

Reputation: 7965

You need to install the Flutter SDK https://flutter.dev/docs/get-started/install/windows#get-the-flutter-sdk

Then in Android Studio, go to settings>plugins, and install the Flutter and Dart plugins.

Then check whether you have provided you SDK path at Settings> Language & Frameworks > Flutter

Upvotes: 0

Related Questions