简体   繁体   English

完成错误:Gradle 任务 assembleDebug 失败,退出代码为 1

[英]Finished with error: Gradle task assembleDebug failed with exit code 1

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我刚刚尝试将 firebase 添加到项目中

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.主要问题似乎是您正在使用已迁移到 AndroidX 的cloud_firestore插件的 0.9.0 版本,但您的项目尚未迁移。 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.因此,这两个选项似乎是使用以前版本的cloud_firestore插件或将您的项目迁移到 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.要将您的项目迁移到 AndroidX,请按照我在上面的评论中提到的链接( Firebase auth plugin crash IOS and android #27422 )和我最初回复的 Android 部分(发布在用户名app-o-matix 下),按照步骤 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-3(我使用 IntelliJ Idea CE 并选择 Swift 和 Kotlin 来创建我的 Flutter 项目):

1) Open the Android portion of your Flutter project in Android Studio. 1) 在 Android Studio 中打开 Flutter 项目的 Android 部分。 Make sure you are using Android Studio 3.3.确保您使用的是 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 .) (我完全关闭了 IntelliJ Idea,打开 Android Studio,点击File > Open ,然后导航到我的 Flutter 项目中的~/IdeaProjects/[my_project]/android文件夹。打开 Android 项目后,Android Studio 开始同步它,出现一条消息/弹出窗口,询问它是否可以更新 Gradle 插件,所以我让它。它已升级到版本3.3.0 。)

2) Add the following 2 lines to the bottom of the [my_project]/android/gradle.properties file: 2) 在[my_project]/android/gradle.properties文件的底部添加以下 2 行:

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 .注意:我不确定android.enableJetifier=true是否可以或应该设置为false Perhaps someone else can clarify under which conditions it should be true vs false .也许其他人可以澄清在哪些条件下它应该是truefalse 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.我认为这与该项目是否有尚未迁移到 AndroidX 的其他库有关,但是,如果我的信念是正确的,我不知道何时将此设置设置为true是否意味着 Android Studio 会将这些库迁移到 AndroidX,或者它会进行代码调整以解决这些库尚不兼容 AndroidX 的事实。 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 . 3) 在 Android Studio 主菜单中,选择Refactor > Migrate to Androidx...将项目的备份保存到 .zip 文件 Follow this with File > Save All and then quit Android Studio.使用File > Save All执行此操作,然后退出 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 .作为迁移后的一项额外措施,在 IntelliJ Idea 中,我运行Tools > Flutter > Flutter CleanFile > Save AllFile > Invalidate Caches and Restart我选择使缓存无效并重新启动,然后在重新启动后Tools > Flutter > Flutter包获取

It seems to be an easy fix.这似乎很容易解决。 Just run flutter doctor command in terminal.只需在终端中运行flutter doctor命令。 then fix the components that required然后修复所需的组件

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:这是一张图片,可以帮助您更清楚地了解要使用的内容:

I had the same problem after cloning a flutter project from github .从 github 克隆一个颤振项目后,我遇到了同样的问题
It usually happens with projects that were created in other machines.它通常发生在其他机器上创建的项目中。
To fix this on Android Studio on MAC, Follow these steps.要在 MAC 上的 Android Studio 上解决此问题,请按照以下步骤操作。

  1. Open your Android Studio preferences(Command + ',') and go to Languages and Frameworks -> Dart打开您的 Android Studio 首选项(Command + ',')并转到 Languages and Frameworks -> Dart

  2. Check "Enable Dart support for the project your_project_name"选中“为项目 your_project_name 启用 Dart 支持”

  3. In "Dart SDK path" click in "…" and navigate to flutter SDK directory.在“Dart SDK 路径”中单击“...”并导航到 Flutter SDK 目录。 Under that directory you'll find "bin/cache/dart-sdk".在该目录下,您会找到“bin/cache/dart-sdk”。 This is the dart sdk path you should use.这是您应该使用的 dart sdk 路径。

  4. Click "Apply"点击“申请”

  5. flutter packages get颤振包得到

  6. flutter run扑跑

Update the package to fix the error from Gradle更新包以修复来自 Gradle 的错误

  1. Open the folder C:\Users\{YourUserName}\.gradle\wrapper\dists , then check the version打开文件夹C:\Users\{YourUserName}\.gradle\wrapper\dists ,然后检查版本

  2. If it is an older version of Gradle, update it from https://gradle.org/ ( Steps to download Gradle )如果是旧版本的 Gradle,请从https://gradle.org/更新(下载 Gradle 的步骤

  3. Download the ZIP file of the latest version, and then unzip it and say yes to replacing any existing files.下载最新版本的 ZIP 文件,然后解压缩并同意替换任何现有文件。

  4. Open Android Studio and run打开 Android Studio 并运行

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.好的,这是您的修复,打开 android sdk 设置并取消选中 Hide Obsolete Packages 并在 sdk 工具中,检查 Android SDK Tools (Obsolete),然后单击确定/应用。 It will download old SDK.它将下载旧的 SDK。 Than Restart the IDE, Run default flutter program on emulator.比重新启动 IDE,在模拟器上运行默认的颤振程序。 This error occurs because flutter isn't compatible with latest Android SDK so you have yo manually install old SDK in Android studio.发生此错误是因为颤振与最新的 Android SDK 不兼容,因此您必须在 Android Studio 中手动安装旧的 SDK。

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)我有上述问题,解决方案是在 C 文件夹中创建项目:名称中没有任何特殊字符(C:\flutter 项目),因为当我遇到此问题时,包含项目的文件夹名称是(D :\平面设计师和程序员\程序员项目)

升级飞镖和颤振插件为我解决了这个问题。

It is very easy.这很容易。 Just follow these steps:只需按照以下步骤操作:

Got android/build.gradle and change the classpath to 3.6 under dependencies.得到 android/build.gradle 并在依赖项下将类路径更改为 3.6。

classpath 'com.android.tools.build:gradle:3.6.0'类路径'com.android.tools.build:gradle:3.6.0'

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之后,您的许可证将全部设置好,您需要做的就是全部接受它们,下载后您将被设置

I face this problem because I forgot to add flutter to my environment variable, so make sure that you add我遇到这个问题是因为我忘记将颤振添加到我的环境变量中,所以请确保添加

C:\src\flutter C:\src\颤动

to the environment variable.到环境变量。

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. Flutter 在第一次运行时需要互联网连接。

Gradle syncing fixed my issue Gradle 同步解决了我的问题

I just opened the file flutter.gradle from the flutter installation folder (/flutter/packages/flutter_tools/gradle) using the Android Studio IDE.我刚刚使用 Android Studio IDE 从flutter安装文件夹(/flutter/packages/flutter_tools/gradle)打开了文件flutter.gradle。 This will prompt the ISE to download and sync the Gradle file.这将提示 ISE 下载并同步 Gradle 文件。 Do restart the IDE, once this is completed.完成后,请重新启动 IDE。

This error was coming in my android studio because AppData folder was a hidden folder.这个错误出现在我的 android studio 中,因为 AppData 文件夹是一个隐藏文件夹。 AppData contains Android SDK files. AppData 包含 Android SDK 文件。 Error was gone after removing hidden mode of AppData.删除 AppData 的隐藏模式后,错误消失了。 You can find AppData folder in C:\Users(YourPc)\AppData.您可以在 C:\Users(YourPc)\AppData 中找到 AppData 文件夹。

将此路径C:\\Program Files\\Android\\Android Studio\\jre\\bin插入您的环境变量 [ 系统变量 ] may be it's work

从 android bios 设置启用 VT x....

My issue was JAVA_HOME variable not correctly configured.我的问题是未正确配置 JAVA_HOME 变量。 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我认为至少在首次构建时需要有效的互联网连接

Just run the app with Start Debugging.只需使用 Start Debugging 运行应用程序。 This solved the problem for me.这为我解决了这个问题。

Try running the project from the command line with "flutter run".尝试使用“flutter run”从命令行运行项目。 Verify that you are on the route of the project location.确认您在项目位置的路线上。

remove import androidx.annotation.Nullable;删除import androidx.annotation.Nullable; from your file.从您的文件中。 then retry!然后重试! :) :)

It is easy to fix.这很容易修复。 You can set 'minSdkVersion 16' to 'minSdkVersion 23' inside the android/app/build.gradle file.您可以在 android/app/build.gradle 文件中将“minSdkVersion 16”设置为“minSdkVersion 23”。

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.我通过转到 android>gradle>wrapper>gradle-wrapper.properties 解决了这个问题,并将分发 url 更改为最新的(当时我遇到这个问题 - version-7.2)gradle 版本。 I worked for me.我为我工作。

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

On terminal first write: "flutter clean ", then once its done, Again write "flutter pub get ", and re-run the app.在终端上首先写:“flutter clean”,然后一旦完成,再次写“flutter pub get”,然后重新运行应用程序。 It will work fine.它会正常工作。

"Invalide cache and restart" did the job for me on Android Studio. “无效缓存并重新启动”在 Android Studio 上为我完成了这项工作。 However this error can happen for many reasons但是,由于多种原因可能会发生此错误

删除flutter文件夹中的.gradle并运行。重置.gradle文件需要一些时间。之后它将成功运行。

if you are a turkish user and keep your projects at desktop (masaüstü), that's the reason you face this issue.如果您是土耳其用户并将您的项目保存在桌面 (masaüstü),这就是您面临此问题的原因。 just drag your file into C/: and try again.只需将文件拖入 C/: 并重试。

Your file path should not contain any non English letter.您的文件路径不应包含任何非英文字母。

To resolve gradle assemble issue.解决 gradle 组装问题。 Run below two command on terminal在终端上运行以下两个命令

  1. flutter clean flutter 清洁
  2. flutter upgrade flutter升级

I had the same issue because of a project that was created on a Mac and then ported to Windows由于在 Mac 上创建然后移植到 Windows 的项目,我遇到了同样的问题


The problem was solved by问题解决了

flutter run

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)如果在最近更新 Andriod 工作室后发生这种情况,请尝试flutter doctor ,如果它显示 [X] Android Studio(版本 2022.1)

GO TO C:\Program Files\Android\Android Studio then copy the content of jbr and paste the content into jre folder GO TO C:\Program Files\Android\Android Studio 然后复制jbr的内容粘贴到jre文件夹

if mac: Go to finder and find Android studio:如果 mac: Go 到 finder 并找到 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右键单击并单击显示 package 内容创建一个名为 jre 的新文件夹复制 jbr 文件夹的内容并将它们粘贴到 jre 文件夹中

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)如果在最近更新 Andriod 工作室后发生这种情况,请尝试 flutter 医生,如果它显示 [X] Android Studio(版本 2022.1)

GO TO C:\Program Files\Android\Android Studio then copy the content of jbr and paste the content into jre folder GO TO C:\Program Files\Android\Android Studio 然后复制jbr的内容粘贴到jre文件夹

This work for me这对我有用

我从 Github 下载了带有 firebase 的 flutter 应用程序代码,并在 android studio 中运行代码,但它不起作用,但我按照@Bhargav Rao 在上述评论中所说的进行操作,然后在 android studio 终端中粘贴flutter pub upgrade之后你会看到一个选项 Pub Upgrade 按下该按钮并等待一分钟,然后您就可以运行该项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异常:Gradle 任务 assembleDebug 失败,退出代码 1 和 dart:html 错误 - Exception: Gradle task assembleDebug failed with exit code 1 and dart:html Error Gradle 任务 assembleDebug 失败,退出代码为 1 flutter - Gradle task assembleDebug failed with exit code 1 flutter GITLAB CI 加载密钥“/dev/fd/63”时出错:格式无效错误:作业失败:退出代码 1 - GITLAB CI Error loading key "/dev/fd/63": invalid format ERROR: Job failed: exit code 1 Python GIT 结帐失败,原因是:退出代码(1) - Python GIT CHeckout failed due to: exit code(1) GitLab CI。 作业失败并出现错误:错误:作业失败:退出状态 9009 - GitLab CI. Job failed with error: ERROR: Job failed: exit status 9009 增加 com.android.tools.build:gradle 版本时任务“:后端:endpointsClientLibs”执行失败 - Execution failed for task ':backend:endpointsClientLibs' when increasing com.android.tools.build:gradle version 任务 ':app:mapDebugSourceSetPaths' 执行失败。 > 评估任务的属性“extraGeneratedResDir”时出错 - Execution failed for task ':app:mapDebugSourceSetPaths'. > Error while evaluating property 'extraGeneratedResDir' of task Firebase 错误:Function 加载用户代码失败(node.js) - Firebase error: Function failed on loading user code (node.js) 任务 ':app:processDebugResources 执行失败 - Execution failed for task ':app:processDebugResources eslintrc.js:4 "parserOptions": { ^ SyntaxError: Unexpected token ':' functions predeploy error: 命令以非零退出代码 2 终止 - eslintrc.js:4 "parserOptions": { ^ SyntaxError: Unexpected token ':' functions predeploy error: Command terminated with non-zero exit code 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM