Skip to content

Can't resolve symbol io.flutter.plugin dependency #19830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abacaj opened this issue Jul 26, 2018 · 76 comments · May be fixed by #167332
Open

Can't resolve symbol io.flutter.plugin dependency #19830

abacaj opened this issue Jul 26, 2018 · 76 comments · May be fixed by #167332
Labels
a: plugins Support for writing, building, and running plugin packages customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team

Comments

@abacaj
Copy link

abacaj commented Jul 26, 2018

Edit from Flutter team:

Please see #19830 (comment). If following these steps still doesn't resolve the imports, please add a comment with your Android Studio version and the output of flutter doctor -v

Original issue:

I'm trying to build a flutter plugin in Android studio using an example template.

When I open the build.gradle in android studio and gradle resolves dependencies I cannot get these symbols to resolve:

I'm not sure what I'm missing as flutter doctor shows I have all checks.

image

@zoechi
Copy link
Contributor

zoechi commented Jul 26, 2018

Please post the output of flutter doctor -v.

@abacaj
Copy link
Author

abacaj commented Jul 26, 2018

PS C:\Users\Anton> flutter doctor -v
[√] Flutter (Channel master, v0.5.8-pre.79, on Microsoft Windows [Version 10.0.17134.48], locale en-US)
    • Flutter version 0.5.8-pre.79 at C:\Users\Anton\Documents\flutter
    • Framework revision bb338ef2c6 (7 days ago), 2018-07-19 07:24:06 -0700
    • Engine revision 5557e3006e
    • Dart version 2.0.0-dev.67.0.flutter-84ca27a09e

[!] Android toolchain - develop for Android devices (Android SDK 28.0.0)
    • Android SDK at C:\Users\Anton\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    X Android license status unknown.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[√] VS Code, 32-bit edition (version 1.24.1)
    • VS Code at C:\Program Files (x86)\Microsoft VS Code
    • Flutter extension version 2.16.0

[!] Connected devices
    ! No devices available

! Doctor found issues in 2 categories.

@abacaj
Copy link
Author

abacaj commented Jul 27, 2018

has anyone else had to deal with this? I am not able to build the project in android studio because of those missing symbols.

@abacaj
Copy link
Author

abacaj commented Jul 27, 2018

I found a workaround by adding the cached flutter.jar file as a library located in flutter\bin\cache\artifacts\engine\android-x64.

Not sure if this is the correct approach since it is the cached version and will need to be manually replaced each time, but it does resolve the symbols for me while editing.

@rahulgul8
Copy link

https://stackoverflow.com/questions/25660166/how-to-add-a-jar-in-external-libraries-in-android-studio

this helped me.

I had to get the jar from flutter\bin\cache\artifacts\engine\android-arm instead of x-86

@zoechi zoechi added the plugin label Aug 21, 2018
@rohitgupta1694
Copy link

I found a workaround by adding the cached flutter.jar file as a library located in flutter\bin\cache\artifacts\engine\android-x64.

Not sure if this is the correct approach since it is the cached version and will need to be manually replaced each time, but it does resolve the symbols for me while editing.

In order to resolve flutter dependencies in Android Studio, we need to a flutter.jar file from the flutter project. I also did the same. But, Is it a good way to do it? @zoechi What effect can it have on our flutter project apart from size?

@remonh87
Copy link

remonh87 commented Jan 4, 2019

I had the same problem but then I found out that the flutter plugin package is recognised when you open the example/android folder in Android studio. Now I can build the project and I can unittest my plugin from Android studio without adding the flutter.jar.

What I did step for step:

  1. delete the .idea folder in the project (do not know if is needed but just to be sure)
  2. in Android Studio click on 'Open an existing Android studio project' and select the folder your_plugin/example/android

If you want to build your library through gradle you can run ./gradlew :your_plugin:assembleDebug

@kartdroid
Copy link

I had the same problem but then I found out that the flutter plugin package is recognised when you open the example/android folder in Android studio. Now I can build the project and I can unittest my plugin from Android studio without adding the flutter.jar.

What I did step for step:

1. delete the .idea folder in the project (do not know if is needed but just to be sure)

2. in Android Studio click on 'Open an existing Android studio project'  and select the folder `your_plugin/example/android`

If you want to build your library through gradle you can run ./gradlew :your_plugin:assembleDebug

I guess this is the proper way for now

@bitsydarel
Copy link

I'm also having the same issue, I'm trying to add flutter to our existing gradle project, it's a really big project.
The flutter plugin need to include another local library which has the platform feature to be used but since gradle can't see the flutter sdk dependency the code does not compile... I don't understand why the flutter team does not provide gradle dependency for the flutter sdk...
We really want to move our ios and android project to flutter its seems that the tooling is not ready yet...

@tolotrasamuel
Copy link

For those who are confused, why opening the the your_plugin/example/android would allow you to fix this issue and continue editing your plugin, here is the explanation:
#11632
Basically, when you open the example/android module, the gradle script will simultaneously attached the plugin directory in the current project and you can edit from there.

@bitsydarel
Copy link

This structure is not great if you want to integrate it to another native project.

This break the following use case :
Mutlit module android root project -> flutter module <- flutter plugins.

If a flutter plugin need to access native features provided by a module in the root project. including the module in the flutter plugin settings.gradle won't work.
The flutter example app won't compile.

The only easy solution would be to publish the module to mavenLocal and then access it in the flutter android library build.gradle...

@amorenew
Copy link

amorenew commented Aug 5, 2019

I still face the same issue in August 2019

[√] Flutter (Channel beta, v1.7.8+hotfix.4, on Microsoft Windows)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.4)

@westracer
Copy link

Same issue. Importing flutter.jar fixes resolving, but then project fails to build.

@amreniouinnovent
Copy link

@zoechi some issues should not be prioritized by how many likes
This issue face only library maintainers, not general users so likes will not be too much however it is an important issue

@davidBarbieri
Copy link

Have the same problem:

Plugin folder is inside the main project root, i'm unable to debug my plugin with native Android code.
I can import the flutter.jar in the plugin, but then the main project won't build

[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale en-GB)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.5)

I see in local properties there is a flutter.sdk variable, with my local flutter sdk installation but it appears to be unused.
I tried to use this variable in the build.gradle file, but got similar errors as importing the flutter.jar file.
P.S. i had the same problem, so i created a new plugin project, but nothing changed

@amreniouinnovent
Copy link

@davidBarbieri just use this line and comment it when you start building
//implementation files('D:\\Programming\\Android\\Tools\\Flutter_SDK\\bin\\cache\\artifacts\\engine\\android-x64\\flutter.jar')

https://github.com/amorenew/flutter_zkteco_fingerprint/blob/master/android/build.gradle

@kishan2612
Copy link

Any solution for this issue ?

@dkaera
Copy link

dkaera commented Oct 25, 2019

As I understand the issue, Android Studio can't find dependency to flutter SDK. A solution which works for me based on this issue - #18983
So, to correctly setup flutter<-->android project you need

  1. add to local.properties file
    flutter.sdk=/Users/<user_name>/development/flutter Flutter SDK home
  2. add to build.gradle file
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

...<your Gradle script>

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

...<your Gradle script>

flutter {
    source '../..'
}

After manipulation above, flutter.jar library should be connected with your project and imports should be available.

@Hixie Hixie added this to the Goals milestone Dec 2, 2019
@Hixie
Copy link
Contributor

Hixie commented Dec 2, 2019

cc @devoncarew

@iapicca iapicca added the customer: crowd Affects or could affect many people, though not necessarily a specific customer. label Feb 6, 2020
keenanwl added a commit to keenanwl/flutter-nfc-reader that referenced this issue Mar 1, 2020
@1ka
Copy link

1ka commented Mar 12, 2020

Thanks @keenawl, your commit is a good example of how to fix this.

On Windows, I also had to define FLUTTER_ROOT environment as it still needed this even though flutter.sdk was defined and read from local.properties was defined.

Also changing the source to be:

flutter {
    source '..'
}

means it can build in VSCode and Android Studio. The ../.. path breaks the gradle build in VSCode for the example.

@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
bsutton added a commit to bsutton/sounds that referenced this issue Jun 27, 2020
@ashwynh21
Copy link

@dkaera....You my friend, are a genius...

@zogol
Copy link

zogol commented May 5, 2023

Unfortunately not. The current workaround I use is that I open the /example folder of the plugin and copy there the content of myplugin.kt in the MainActivity.kt. edit there and copy the changes afterwards into the plugin.kt and reset the MainActivity.kt. a very strange process, but the only one that currently works for me.

@cyberpwnn
Copy link

Why is this so hard? Why is this 2 years old? Why am I unable to use my google editor for a google sdk that is supposed to support this? None of the workarounds work here. Can we talk solutions?

@gowthamaanp
Copy link

As for now, the temporary workaround mentioned in this link works: https://stackoverflow.com/questions/46289542/flutter-dependency-in-java-plugin

This method resolves the problem. But comment the implementation line in build.gradle file after building the plugin. If you run the example app without commenting the line, it produces Duplicate dependencies error as the flutter source is included in the example app's build.gradle file.

This workaround is working for me. Go through the link and try the steps. Also, comment the implementation line after building the plugin.

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 8, 2023
@gmackall
Copy link
Member

gmackall commented Aug 22, 2023

Instructions from a new plugin, with android platform code:

  1. Create a new plugin using the template: flutter create --org com.example --template=plugin --platforms=android -a java sample (in the screenshots, I named it mackall_example, so that is what will show up).
  2. Open the <Rest of path>/sample/example/android subdirectory in Android Studio: Screenshot 2023-08-22 at 11 28 51 AM
  3. You should see the following in the "Project" section:
Screenshot 2023-08-22 at 11 29 21 AM
  1. From <Rest of path>/sample/example, run flutter build apk --config-only to generate the necessary config files. Note flutter run or flutter build while targeting android would also suffice.
  2. Sync your Gradle files in Android Studio (on mac, this is File>Sync Project with Gradle Files).
  3. You should now see the following, with dependencies resolved correctly:
Screenshot 2023-08-22 at 11 33 18 AM

@carman247
Copy link

@gmackall

You sir are a life saver. Thank you so much!

@JarvanMo
Copy link

JarvanMo commented Dec 7, 2023

@gmackall You really save my life! Thank you.

@hardik-malhotra007
Copy link

Screenshot 2024-02-22 at 12 15 31 PM

I have done the same steps @gmackall has suggested. but still, I'm able to see different structures.

@lushangkan

This comment was marked as abuse.

@Nilav2608
Copy link

Damnn Got the same error again after a year. I have been building a big project and suddenly one day the android folder started appearing in red, everything was fine before.

Folder structure

image

Error:

image

Tried as many suggestions to solve it but failed!

@rekire
Copy link
Contributor

rekire commented May 21, 2024

The solution is just to open the example/android project that one includes the plugin itself. Crazy that this is still a thing.

@Ldev007
Copy link

Ldev007 commented May 21, 2024

Hi @Nilav2608 and others facing the same issue, the only possible solution which worked for me was to edit the plugin related files from within the following path :
<flutter-project>/example/android

Also, if you previously tried accessing the android folder within your flutter app i.e <flutter-project>/android in android studio then (although according to me it didn't make any difference) as suggested you should delete the existing .idea folder within that as well to prevent any conflicts and then restart android studio thereafter opening <flutter-project>/example/android

@subzero911
Copy link

subzero911 commented May 30, 2024

Thanks @Ldev007 , that's the only solution which helped me

  1. Open the example/android
  2. Navigate to the main plugin package in the left menu and edit the code.

image

If I open the sdk_ums_flutter/android directly, it seems not to see the Flutter libraries.

It's a shame, 6 years have passed, and this bug is still not resolved.

@SEGVeenstra
Copy link

Thanks @Ldev007 , that's the only solution which helped me

  1. Open the example/android
  2. Navigate to the main plugin package in the left menu and edit the code.

How do you even get that plugin folder to show up?
I tried all the things like deleting the .idea stuff and building the project first, basically everything that is mentioned in the docs:

Step 2b: Add Android platform code (.kt/.java)
We recommend you edit the Android code using Android Studio.

Before editing the Android platform code in Android Studio, first make sure that the code has been built at least once (in other words, run the example app from your IDE/editor, or in a terminal execute cd hello/example; flutter build apk --config-only).

Then use the following steps:

Launch Android Studio.
Select Open an existing Android Studio Project in the Welcome to Android Studio dialog, or select File > Open from the menu, and select the hello/example/android/build.gradle file.
In the Gradle Sync dialog, select OK.
In the Android Gradle Plugin Update dialog, select Don't remind me again for this project.
The Android platform code of your plugin is located in hello/java/com.example.hello/HelloPlugin.

But I only get the App project...

@yullg
Copy link

yullg commented Jun 12, 2024

我在Windows系统下遇到过相同的问题,似乎是项目代码和PUB的缓存目录在不同的磁盘分区导致的。通过PUB_CACHE环境变量将PUB缓存目录修改为和项目代码在相同的磁盘分区后恢复正常。

@Code-Remote
Copy link

I've tried with different Android Studio versions (Koala rc, Jellyfish patch 2 and 1, Iguana) and different flutter versions (3.22.2 and 3.13.8) and I keep on getting the same unresolved errors.

I checked stack overflow(https://stackoverflow.com/questions/56965783/flutter-plugin-development-unresolved-reference-io) and all I can find is people saying to delete the .idea folder and open the android folder that is inside of my flutter project as a separate project in Android Studio, but still the lines stay red and keep the "Unresolved reference: io"

Also, when I have my flutter project open and navigate to the MyPlugin.kt file inside of the android folder that is in the root of my Flutter project it shows this message "Open for Editing in Android Studio", but when I click it nothing happens.

@Code-Remote
Copy link

@yullg, can you explain the exact steps you've taken to do that and how that can be done on macOS?

yullg's message translated > I encountered the same problem in Windows system. It seems that the project code and PUB cache directory are in different disk partitions. After changing the PUB cache directory to the same disk partition as the project code through the PUB_CACHE environment variable, it returned to normal.

@Code-Remote
Copy link

@SEGVeenstra found the solution, you will never guess, apparently if you read the documentation very carefully (😅 🤦‍♂️) You will succeed!

https://docs.flutter.dev/packages-and-plugins/developing-packages#step-2b-add-android-platform-code-kt-java

When creating a flutter plugin project called 'hello'

Before editing the Android platform code in Android Studio, first make sure that the code has been built at least once (in other words, run the example app from your IDE/editor, OR in a terminal execute cd hello/example; flutter build apk --config-only).

After that

Launch Android Studio.
Select Open an existing Android Studio Project in the Welcome to Android Studio dialog, or select File > Open from the menu, and select the hello/example/android/build.gradle file.
In the Gradle Sync dialog, select OK.
In the Android Gradle Plugin Update dialog, select Don't remind me again for this project.
The Android platform code of your plugin is located in hello/java/com.example.hello/HelloPlugin.

This worked for me!

@yusuphwickama
Copy link

@Code-Remote,

At this point, the plugin generation command should automatically run the extra flutter build apk --config-only command after generating the project.

@rekire
Copy link
Contributor

rekire commented Jul 25, 2024

I might found a nice workaround. Check my comment here: flutter/flutter-intellij#7487 (comment)

@canxin121
Copy link

Do not open project/android, instead open project/example/android.

@rekire rekire linked a pull request Apr 17, 2025 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: plugins Support for writing, building, and running plugin packages customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.