问题
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
回答1:
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 tofalse
. Perhaps someone else can clarify under which conditions it should betrue
vsfalse
. 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 totrue
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.
回答2:
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.
Open your Android Studio preferences(Command + ',') and go to Languages and Frameworks -> Dart
Check "Enable Dart support for the project your_project_name"
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.
Click "Apply"
flutter packages get
flutter run
回答3:
It seems to be an easy fix. Just run "fluter doctor" in terminal. then fix the components that required
回答4:
the Error From Gradle Package Version To Fix Update The Package
Step 1: Open Folder gradle Path C:\Users\{YourUserName}\.gradle\wrapper\dists
then Chick The Version.
If it Was Old Update it from gradle.org
Grandle New Version Download
Download The Lastest Version ZIP File And unzip it With accepting Files Replacing.
And OPEN ANDRIOD STEDIO and run
回答5:
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.
回答6:
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.
回答7:
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.
回答8:
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.
回答9:
Insert this path C:\Program Files\Android\Android Studio\jre\bin
in your environment variables [ Systems variables ] may be it's work
回答10:
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.
来源:https://stackoverflow.com/questions/54510465/finished-with-error-gradle-task-assembledebug-failed-with-exit-code-1