如何运行我的 Flutter 应用程序。任务 ':path_provider_android:compileDebugJavaWithJavac' 执行失败

问题描述 投票:0回答:3

使用 Firebase 设置 Flutter 项目后,我无法运行我的应用程序。我尝试使用

flutter clean
重建应用程序,还尝试更改各种 Java 版本,目前为 Java v17。我试过了

./gradlew clean  
./gradlew build  

使用 Gradle 构建成功。但当我再次运行时,它显示了同样的问题。

Launching lib\main.dart on Pixel 8 Pro in debug mode...
Warning: SDK processing. This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':path_provider_android:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':path_provider_android:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: C:\Users\nisha\AppData\Local\Android\sdk\platforms\android-34\core-for-system-modules.jar.
         > Error while executing process C:\Program Files\Android\Android Studio\jbr\bin\jlink.exe with arguments {--module-path C:\Users\nisha\.gradle\caches\transforms-3\01761d3d44a592c784df1715afe57f9c\transformed\output\temp\jmod --add-modules java.base --output C:\Users\nisha\.gradle\caches\transforms-3\01761d3d44a592c784df1715afe57f9c\transformed\output\jdkImage --disable-plugin system-modules}

* 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 2m 12s
Running Gradle task 'assembleDebug'...                            133.6s
Error: Gradle task assembleDebug failed with exit code 1

我该如何解决这个问题?是什么原因导致这个问题?

java flutter dart gradle
3个回答
0
投票

将项目与 firebase 连接时的有用链接:
此链接逐步说明了您需要执行的操作 CLI

  1. npm install -g firebase-tools
  2. dart pub global activate flutterfire_cli
  3. flutterfire configure

0
投票

这些警告

warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release

androidJdkImage
中的错误表明,尽管您声称您使用java v17,但实际上使用的是java 21。 您有几个选择:

  1. 强制使用 java 17 来实现 flutter。尽管您使用的是 java 17(我相信 JAVA_HOME 指向它,对吧?),flutter 默认情况下使用最新 Android Studio 中的 Java(如果存在)。这可能是您的问题和这种奇怪行为的关键。

您可以使用此命令强制使用 java 17:

flutter config --jdk-dir="path_to_Java_17_home"
  1. 实际上,您可以通过将
    settings.gradle
    中的 AGP(android Gradle 插件)更新到更新版本来使您的 Android 项目适应 Java 21。任何从
    8.3.2
    开始的东西都应该有效。

当然,在选择其中任何一个选项后,请制作

flutter clean
flutter pub get


0
投票

我也有同样的问题。他们在这里做了详细的实验。您可以通过此链接进行检查。

© www.soinside.com 2019 - 2024. All rights reserved.