27
Launching lib\main.dart on HTC One M9PLUS in debug mode... Initializing gradle... Resolving dependencies... Gradle task 'assembleDebug'... registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:9: error: cannot find symbol import androidx.annotation.NonNull;
                          ^   symbol:   class NonNull   location: package androidx.annotation C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:10: error: cannot find symbol import androidx.annotation.Nullable;
                          ^   symbol:   class Nullable   location: package androidx.annotation C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:253: error: cannot find symbol
          public void onFailure(@NonNull Exception e) {
                                 ^   symbol: class NonNull C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:274: error: cannot find symbol
                    public Void apply(@NonNull Transaction transaction)
                                       ^   symbol: class NonNull C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:272: error: cannot find symbol
                    @Nullable
                     ^   symbol: class Nullable C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:503: error: cannot find symbol
                    public void onFailure(@NonNull Exception e) {
                                           ^   symbol: class NonNull C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.9.0\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java:558: error: cannot find symbol
                    public void onFailure(@NonNull Exception e) {
                                           ^   symbol: class NonNull 7 errors

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':cloud_firestore:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 26s Finished with error: Gradle task assembleDebug failed with exit code 1

I just tried to add the firebase to the project

ROOT
  • 11,363
  • 5
  • 30
  • 45
asimsharf
  • 447
  • 1
  • 5
  • 14
  • 1
    Create a new project import current work to new project. Then import firebase and it's dependencies afresh. Always works for me – Taio Feb 04 '19 at 05:32
  • Oooh please tell me how to do that cuz i did everything that i know – asimsharf Feb 04 '19 at 06:23
  • 1
    You have to put in a little effort. This is just my method of resolving most Gradle errors in Flutter. Create a New project and follow the process to add Firestore to a flutter project. It is always well documented, the process. Run the new project and see if the error pops up again. – Taio Feb 04 '19 at 06:46
  • Asim, I outline my steps for getting my Flutter Android app to build successfully here: [Firebase auth plugin crash IOS and android #27422](https://github.com/flutter/flutter/issues/27422) (scroll down to the two posts by *app-o-matix*). Take a look and see if it helps. – eggroll Feb 04 '19 at 15:26

28 Answers28

17

The primary problem looks to be that you are using version 0.9.0 of the cloud_firestore plugin which has been migrated to AndroidX, but your project has not been migrated. So, it would appear the two options are to either use the previous version of the cloud_firestore plugin or migrate your project to AndroidX.

To migrate your project to AndroidX, follow the link I mention in my comment above (Firebase auth plugin crash IOS and android #27422) and under the Android section of my initial response (posted under username app-o-matix), follow Steps 1-3. The remaining steps and follow up post may be of help in avoiding additional problems.

Here are Steps 1-3 from the linked page (I use IntelliJ Idea CE and select Swift and Kotlin in creating my Flutter projects):

1) Open the Android portion of your Flutter project in Android Studio. Make sure you are using Android Studio 3.3. (I closed IntelliJ Idea altogether, opened Android Studio, clicked on File > Open, and navigated to the ~/IdeaProjects/[my_project]/android folder in my Flutter project. Upon opening the Android project followed by Android Studio starting to sync it, a message/pop-up appeared asking if it could update the Gradle plugin, so I let it. It was upgraded to version 3.3.0.)

2) Add the following 2 lines to the bottom of the [my_project]/android/gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

Note: I'm not sure if android.enableJetifier=true could have been, or should have been, set to false. Perhaps someone else can clarify under which conditions it should be true vs false. I believe it has something to do with whether or not the project has additional libraries that haven't yet been migrated to AndroidX, but, if my belief is correct, I don't know if when this setting is set to true it means Android Studio will migrate these libraries to AndroidX or that it will make code adjustments to account for the fact that the libraries aren't yet AndroidX compatible. Or maybe I'm totally wrong and it is something else altogether.

3) In the Android Studio main menus, select Refactor > Migrate to Androidx..., saving a backup of your project to a .zip file. Follow this with File > Save All and then quit Android Studio.

As an extra measure after the migration, in IntelliJ Idea I run Tools > Flutter > Flutter Clean, File > Save All, File > Invalidate Caches and Restart where I choose to both invalidate caches and restart, then after the restart Tools > Flutter > Flutter Packages Get.

eggroll
  • 1,049
  • 9
  • 18
6

This often happens when you try to re open or clone a project that created a while ago. to fix it all you need to do is this :

flutter pub upgrade

Here is an image to help you understand what to use more clearly:

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
ali ahmadi
  • 61
  • 1
  • 1
4

I had the same problem after cloning a flutter project from github .
It usually happens with projects that were created in other machines.
To fix this on Android Studio on MAC, Follow these

steps.

  1. Open your Android Studio preferences(Command + ',') and go to Languages and Frameworks -> Dart

  2. Check "Enable Dart support for the project your_project_name"

  3. In "Dart SDK path" click in "…" and navigate to flutter SDK directory. Under that directory you'll find "bin/cache/dart-sdk". This is the dart sdk path you should use.

  4. Click "Apply"

  5. flutter packages get

  6. flutter run

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
Ishwar Chandra Tiwari
  • 5,099
  • 6
  • 22
  • 41
4

It seems to be an easy fix. Just run flutter doctor command in terminal. then fix the components that required

Kishan Viramgama
  • 893
  • 1
  • 11
  • 23
1

Update the package to fix the error from Gradle

  1. Open the folder C:\Users\{YourUserName}\.gradle\wrapper\dists, then check the version

  2. If it is an older version of Gradle, update it from https://gradle.org/ (Steps to download Gradle)

  3. Download the ZIP file of the latest version, and then unzip it and say yes to replacing any existing files.

  4. Open Android Studio and run

shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34
Omar bakhsh
  • 896
  • 11
  • 18
1

Ok so here is your fix, open android sdk settings and uncheck Hide Obsolete Packages and in sdk tools, Check Android SDK Tools (Obsolete) than click ok/apply. It will download old SDK. Than Restart the IDE, Run default flutter program on emulator. This error occurs because flutter isn't compatible with latest Android SDK so you have yo manually install old SDK in Android studio.

1
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
The system cannot find the path specified.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Exception: Gradle task assembleDebug failed with exit code 1

I have the above issue and the solution was to create the project in folder in C: with out any special characters in it's name (C:\flutter projects) because when I have this issue the folder name which contain the project was that (D:\Graphic designer & Programmer\Programmer project)

AlexisG
  • 2,476
  • 3
  • 11
  • 25
1

Upgrading dart and flutter plugin resolved the issue for me.

Sriraksha
  • 459
  • 1
  • 8
  • 15
1

It is very easy. Just follow these steps:

Got android/build.gradle and change the classpath to 3.6 under dependencies.

classpath 'com.android.tools.build:gradle:3.6.0'

Habeeb E Sadeed
  • 119
  • 1
  • 2
  • 7
1

I had the same problem and I went to my terminal and ran this command:

$ flutter doctor

you will be shown the problems you have on packages which to my thinking could be the licences so run the command below:

$ flutter doctor --android-licences

After that your licences will all be set all you need to do is accept them all and you will be set after they have been downloaded

Isuru
  • 30,617
  • 60
  • 187
  • 303
Lamech Desai
  • 709
  • 6
  • 11
1

To resolve gradle assemble issue. Run below two command on terminal

  1. flutter clean
  2. flutter upgrade
Sumeet Solse
  • 61
  • 1
  • 2
1

If this happened to you after the recent update of Android studio try flutter doctor and if it shows [X] Android Studio (version 2022.1)

GO TO C:\Program Files\Android\Android Studio then copy the content of jbr and paste the content into jre folder

if mac: Go to finder and find Android studio:

right click and click show package contents Create a new folder called jre copy the contents of the jbr folder and paste them into jre folder

Big_Boulard
  • 799
  • 1
  • 13
  • 28
  • 1
    Thank you !! This saved my day ... and this is how I disabled auto-updates for everything. After losing many hours to a problem caused by an "Update" which supposed to fix stuff not break !! – KaO Feb 17 '23 at 19:10
0

I face this problem because I forgot to add flutter to my environment variable, so make sure that you add

C:\src\flutter

to the environment variable.

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
Akash Singh
  • 21
  • 2
  • 4
0

I was not connected to the internet and had this error. Just connect to the internet and run your app again. Flutter needs an internet connection on the first run.

Abdurahman Popal
  • 2,859
  • 24
  • 18
0

Gradle syncing fixed my issue

I just opened the file flutter.gradle from the flutter installation folder (/flutter/packages/flutter_tools/gradle) using the Android Studio IDE. This will prompt the ISE to download and sync the Gradle file. Do restart the IDE, once this is completed.

Augustine
  • 1,714
  • 1
  • 17
  • 21
0

This error was coming in my android studio because AppData folder was a hidden folder. AppData contains Android SDK files. Error was gone after removing hidden mode of AppData. You can find AppData folder in C:\Users(YourPc)\AppData.

Menol
  • 1,230
  • 21
  • 35
0

remove import androidx.annotation.Nullable; from your file. then retry! :)

Paul Lemarchand
  • 2,068
  • 1
  • 15
  • 27
RITTIK
  • 149
  • 1
  • 5
0

It is easy to fix. You can set 'minSdkVersion 16' to 'minSdkVersion 23' inside the android/app/build.gradle file.

0

This error troubled me for a week. I finally fixed it by updating the grade version I was using. I solved it by going to android>gradle>wrapper>gradle-wrapper.properties and I changed the distribution url to the latest(at the time I faced this problem- version-7.2) gradle version. I worked for me.

distributionUrl=https://services.gradle.org/distributions/gradle-7.2-all.zip

Abhu
  • 1
0

On terminal first write: "flutter clean ", then once its done, Again write "flutter pub get ", and re-run the app. It will work fine.

0

"Invalide cache and restart" did the job for me on Android Studio. However this error can happen for many reasons

Florian K
  • 2,033
  • 1
  • 9
  • 21
0

Delete .gradle in your flutter folder and run.It will take some to reset the .gradle file.After that it will run successfully.

0

if you are a turkish user and keep your projects at desktop (masaüstü), that's the reason you face this issue. just drag your file into C/: and try again.

Your file path should not contain any non English letter.

omeroglu
  • 21
  • 2
0

I had the same issue because of a project that was created on a Mac and then ported to Windows


The problem was solved by

flutter run
Bin Khanjar
  • 87
  • 1
  • 4
0

If this happened to you after the recent update of Andriod studio try flutter doctor and if it shows [X] Android Studio (version 2022.1)

GO TO C:\Program Files\Android\Android Studio then copy the content of jbr and paste the content into jre folder

This work for me

0

You have to accept all the android licenses. You can check if the licenses are already installed using this command:

flutter dotor

and to install the licenses you can use this command:

flutter doctor --android-licenses

user1210
  • 61
  • 1
  • 4
-1

My issue was JAVA_HOME variable not correctly configured. I change it from

C:\Program Files\Java\jdk1.8.0_181\bin

to

C:\Program Files\Java\jdk1.8.0_181

and i think an active internet connection is required at least for first build

-1

Try running the project from the command line with "flutter run". Verify that you are on the route of the project location.