简体   繁体   English

Flutter:任务“:app:compileDebugKotlin”执行失败

[英]Flutter: Execution failed for task ':app:compileDebugKotlin'

I tried running the default flutter app from flutter create on my android device but it throws me an error.我尝试在我的 android 设备上运行flutter 创建的默认 flutter 应用程序,但它给我一个错误。 Can someone help?有人可以帮忙吗?

Launching lib\main.dart on SM G610F in debug mode... Running Gradle task 'assembleDebug'...在调试模式下在 SM G610F 上启动 lib\main.dart... 运行 Gradle 任务“assembleDebug”...

FAILURE: Build failed with an exception. FAILURE:构建失败并出现异常。

  • What went wrong: Execution failed for task ':app:compileDebugKotlin'.出了什么问题:任务':app:compileDebugKotlin'执行失败。

    Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.无法解析配置“:app:debugCompileClasspath”的所有工件。 . . . . . .

  • Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志 output。 Run with --scan to get full insights.运行 --scan 以获得完整的见解。

  • Get more help at https://help.gradle.orghttps://help.gradle.org获得更多帮助

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

This is my flutter doctor:这是我的 flutter 医生:

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.10586], locale en-US) • Flutter version 1.12.13+hotfix.5 at E:\flutter\flutter • Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800 • Engine revision 2994f7e1e6 • Dart version 2.7.0 [√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.10586], locale en-US) • Flutter version 1.12.13+hotfix.5 at E:\flutter\flutter • Framework修订版 27321ebbad(6 周前),2019-12-10 18:15:01 -0800 • 引擎修订版 2994f7e1e6 • Dart 版本 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at C:\Users\208046\AppData\Local\Android\sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 29.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03) • All Android licenses accepted. [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at C:\Users\208046\AppData\Local\Android\sdk • Android NDK location not configured (optional; useful for native profiling support ) • Platform android-29, build-tools 29.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483- b03) • 接受所有 Android 许可证。

[√] Android Studio (version 3.5) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 42.1.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03) [√] Android Studio (version 3.5) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 42.1.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483 -b03)

[√] VS Code, 64-bit edition (version 1.41.1) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.7.1 [√] VS Code,64 位版本(版本 1.41.1) • VS Code 位于 C:\Program Files\Microsoft VS Code • Flutter 扩展版本 3.7.1

[√] Connected device (1 available) • SM G610F • 33005566b2b5c3df • android-arm • Android 8.1.0 (API 27) [√] 连接设备(1 个可用) • SM G610F • 33005566b2b5c3df • android-arm • Android 8.1.0 (API 27)

• No issues found! • 未发现任何问题!

edit: for my complete logs you can see here:编辑:对于我的完整日志,您可以在这里看到:

Flutter github issues Flutter github 问题

Go to your build.gradle file in the root of your Android directory and upgrade your Kotlin_version to the latest.转到 Android 目录根目录中的build.gradle文件,并将Kotlin_version升级到最新版本。 As of the time of typing this, the latest is 1.5.10, so it should look like this:截至打字时,最新的是 1.5.10,所以它应该是这样的:

ext.kotlin_version = '1.5.10'

通过删除android/.gradle解决了问题,然后在调试中运行应用程序

A possible fix can be upgrading the project/android/build.gradle Steps to fix,一个可能的修复可以是升级项目/android/build.gradle 修复步骤,

  1. flutter clean扑干净
  2. Delete android/.gradle删除 android/.gradle
  3. Go to android/build.gradle, upgrade ext.kotlin_version to latest.转到 android/build.gradle,将ext.kotlin_version升级到最新版本。 In my case(1.3.0 -> 1.5.10), ext.kotlin_version = '1.5.10'在我的情况下(1.3.0 -> 1.5.10), ext.kotlin_version = '1.5.10'

After doing this as well, I was getting `A problem occurred evaluating project ':app'.在这样做之后,我得到了`评估项目':app'时出现问题。

Failed to apply plugin [id 'kotlin-android'] The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin.无法应用插件 [id 'kotlin-android'] 当前 Gradle 版本 5.6.2 与 Kotlin Gradle 插件不兼容。 Please use Gradle 6.1 or newer, or the previous version of the Kotlin plugin.`请使用 Gradle 6.1 或更新版本,或之前版本的 Kotlin 插件。`

To fix this,为了解决这个问题,

  1. Go to android/gradle/wrapper/gradle-wrapper.properties转到android/gradle/wrapper/gradle-wrapper.properties
  2. Update the distributionUrl to the latest version.In my case((5.6.2 -> 6.1.1) it is, distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip将distributionUrl更新到最新版本。在我的情况下((5.6.2 -> 6.1.1), distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

For me, I found that when building that 2 different MainActivity.kt files were in andriod/app/src/main/kotlin .对我来说,我发现在构建 2 个不同的 MainActivity.kt 文件时,它们位于andriod/app/src/main/kotlin中。 One had a default MainActivity.kt file with the package name that was originally generated for my project.一个有一个默认的 MainActivity.kt 文件,其中包含最初为我的项目生成的包名称。 Something like 'example.project_name' .类似 'example.project_name' 的东西。 The other one had what I changed my project name into.另一个是我将项目名称更改为的。 I went ahead and deleted the folder with the MainActivity.kt containing the import starting with 'example.project_name' and that resolved the issue for me.我继续删除了 MainActivity.kt 的文件夹,该文件夹包含以“example.project_name”开头的导入,这为我解决了这个问题。

in android folder of your project run in terminal在终端中运行的项目的 android 文件夹中

gradlew clean

Then build.然后构建。 This worked for me.这对我有用。

It was fixed after I upgraded my build.gradle file ext.kotlin_version = '1.5.10'在我升级我的 build.gradle 文件ext.kotlin_version = '1.5.10'后它已修复

First of all run首先运行

flutter clean
flutter pub get

Go to andriod/build.gradle then upgrade ext.kotlin_version转到andriod/build.gradle然后升级ext.kotlin_version

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
} 

I solved it.我解决了。 It was because of my network blocked non secured http download request.这是因为我的网络阻止了不安全的 http 下载请求。 I changed my network and the gradle build completed itself.我改变了我的网络,gradle build 自己完成了。

我通过在根build.gradle文件中升级 kotlin 版本来解决它:

ext.kotlin_version = '1.5.10'

First of make sure that you have latest version of flutter.首先确保你有最新版本的颤振。 For confirmation, please run flutter upgrade in command prompt / terminal:如需确认,请在命令提示符/终端运行flutter upgrade

flutter upgrade

Then visit the site Click Here and copy the new latest version of kotlin.然后访问站点Click Here并复制新的最新版本的 kotlin。 For now: in March 02, 2022 current kotlin version is 1.6.10目前:2022 年 3 月 2 日,当前 kotlin 版本为1.6.10

Then after it:然后在它之后:

-> Go to android/build.gradle
-> change to ext.kotlin_version = '1.6.10'

Click here to view Screenshot example单击此处查看屏幕截图示例

在我通过运行flutter upgrade升级我的Flutter后修复了它

I have been facing this issue for couple of hours.我已经面临这个问题几个小时了。 At the end right now my issue solved by executing following steps -最后,我的问题通过执行以下步骤解决了 -

- change Settings -> Build, Execution, Development -> Compiler -> Kotlin Compiler -> Kotlin to JVM -> check Enable incremental comilation -> Target JVM version 1.6 to 1.8

- add to build.gradle under repositories in both buildscript and allprojects section

maven {
        url 'http://download.flutter.io'
    }

-and lastly run on command line 'flutter pub cache repair'

在此处输入图像描述

I got the problem after migrating to null-safety.迁移到零安全后我遇到了问题。 I fixed it by updating the kotlin version in the file android\build.gradle我通过更新文件 android\build.gradle 中的 kotlin 版本来修复它

ext.kotlin_version = '1.3.50'

Then run 'flutter clean' and the app worked fine.然后运行“flutter clean”,应用程序运行良好。

只需将 ext.kotlin.version 从您拥有的任何版本增加到“1.4.32”或任何可用的最新版本kotline 版本

I Update Flutter from 2.10.4 to Flutter 3.0.0 and I found All My Project Has Same Error我将 Flutter 从 2.10.4 更新到 Flutter 3.0.0,我发现我的所有项目都有相同的错误

ensure that your ext.kotlin_version is '1.6.10'确保您的 ext.kotlin_version 为 '1.6.10'

ext.kotlin_version = '1.6.10'

and run in terminal并在终端中运行

flutter pub cache repair

and show that your libraries in pubspec.yamel take last version and run in terminal并显示您在pubspec.yamel中的库采用最新版本并在终端中运行

1 - flutter clean 1 - flutter clean

2 - flutter pub get 2 - flutter pub get

in android studio open File --> invalidate cashes..在 android studio 中打开 File --> invalidate cashes..

this worked for me !!这对我有用!

if this not work for you you may be need to如果这对您不起作用,您可能需要

Delete android/.gradle

thank you .谢谢你 。

当我在命令行提示符下运行颤振升级时,它已修复并运行我的应用程序.. 试试看

Faced the same issue: Execution failed for task ':app:compileDebugKotlin'.面临同样的问题:任务':app:compileDebugKotlin'的执行失败。 Execution failed for task ':app:compileDebugKotlin'.任务 ':app:compileDebugKotlin' 执行失败。

solution: Changed the company domain with only one dot.解决方案:只用一个点更改公司域。 solution解决方案

I was using JRE for Java.我正在为 Java 使用 JRE。 I just install the AdoptOpenJDK 11 and it works我只是安装了 AdoptOpenJDK 11 并且它可以工作

I encountred the same problem and tried all the solutions proposed here in this post ... and still not working.我遇到了同样的问题并尝试了这篇文章中提出的所有解决方案......但仍然无法正常工作。

but only after upgrading the packages in pubspec.yaml with:但只有在升级 pubspec.yaml 中的软件包之后:

flutter pub upgrade

it worked !!有效 !!

For me, my package name imported twice automatically in MainActivity file under app>main>kotlin directory.对我来说,我的包名在 app>main>kotlin 目录下的 MainActivity 文件中自动导入了两次。 I just delete duplicates and it works fine now!我只是删除重复项,现在可以正常工作了!

在我的情况下更新到最新版本是 1.6.10 或创建虚拟项目并检查 android/build.gradle 并更新。

ext.kotlin_version = '1.6.10'

In our case, the package flutter_appcenter_bundle caused this issue.在我们的案例中,package flutter_appcenter_bundle导致了这个问题。

To fix it, you need to run flutter precache .要修复它,您需要运行flutter precache

This needs to be done only once and it will be effective as long as the Flutter version remains unchanged and the precached artifacts are not deleted (eg by deleting the Flutter root folder).只需执行一次,只要 Flutter 版本保持不变且未删除预缓存的工件(例如,通过删除 Flutter 根文件夹),它将有效。

Also, the environment variable FLUTTER_ROOT needs to be set to the Flutter root folder.此外,环境变量FLUTTER_ROOT需要设置为 Flutter 根文件夹。 On Windows it's usually C:\src\flutter .在 Windows 上,它通常是C:\src\flutter

If you use AndroidStudio, you can do that in Settings > Languages & Frameworks > Flutter .如果您使用 AndroidStudio,您可以在Settings > Languages & Frameworks > Flutter中执行此操作。

If you don't use AndroidStudio, you need to set FLUTTER_ROOT manually.如果不使用 AndroidStudio,则需要手动设置FLUTTER_ROOT

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

相关问题 任务执行失败':app:compileDebugKotlin' - Execution failed for task ':app:compileDebugKotlin' 无法运行 Flutter 应用程序,错误:任务“:应用程序:compileDebugKotlin”执行失败 - Cant Run Flutter App, Error:Execution failed for task ':app:compileDebugKotlin' flutter hello_world 项目:任务 ':app:compileDebugKotlin' 执行失败 - flutter hello_world project: execution failed for task ':app:compileDebugKotlin' Flutter:任务 ':location:compileDebugKotlin' 执行失败 - Flutter: Execution failed for task ':location:compileDebugKotlin' 错误:任务“:app:compileDebugKotlin”执行失败 - Error:Execution failed for task ':app:compileDebugKotlin' Flutter / Android / Gradle - 任务:app:compileDebugKotlin FAILED - Flutter / Android / Gradle - Task :app:compileDebugKotlin FAILED Flutter 编译错误 - 任务 ':flutter_paystack:compileDebugKotlin' 执行失败 - Flutter compilation error - Execution failed for task ':flutter_paystack:compileDebugKotlin' Flutter: 任务 ':agora_rtc_engine:compileDebugKotlin' 执行失败 - Flutter: Execution failed for task ':agora_rtc_engine:compileDebugKotlin' 北极狐 3.1 RC1 - 任务 ':app:compileDebugKotlin' 执行失败 - Arctic fox 3.1 RC1 - Execution failed for task ':app:compileDebugKotlin' 使用Firebase时,任务app.compileDebugKotlin的Android执行失败 - Android Execution failed for task app.compileDebugKotlin when firebase is used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM