为什么在 Android Studio 的 pubspec.yaml 中添加任何包后 Flutter 就无法编译?

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

我在 Android Studio 中有一个基本的 Flutter 项目,但是每当我添加任何外部包(例如:google_fonts)时,编译都会失败并出现 Gradle 错误。

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...

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\dimitri\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\dimitri\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\temp\jmod --add-modules java.base --output C:\Users\dimitri\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\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 26s
Error: Gradle task assembleDebug failed with exit code 1

以下是已安装版本的详细信息:
Flutter/Dart 版本:

flutter --version
Flutter 3.24.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision dec2ee5c1f (5 days ago) • 2024-11-13 11:13:06 -0800
Engine • revision a18df97ca5
Tools • Dart 3.5.4 • DevTools 2.37.3

Gradle/Java 版本:

PS E:\DevEnv\flutter\projects\doit\lesson01\android> ./gradlew -version

------------------------------------------------------------
Gradle 8.3
------------------------------------------------------------

Build time:   2023-08-17 07:06:47 UTC
Revision:     8afbf24b469158b714b36e84c6f4d4976c86fcd5

Kotlin:       1.9.0
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.12 (Oracle Corporation 17.0.12+8-LTS-286)
OS:           Windows 11 10.0 amd64

请告知问题根源在哪里以及如何解决?

flutter android-studio gradle android-gradle-plugin flutter-dependencies
1个回答
0
投票

尝试将此 path_provider 插件添加到您的 pubspec.yaml 中。我怀疑

google_fonts
插件与另一个缺少的插件依赖项冲突。

然后在添加该插件后按照常规方法进行操作,然后重建您的项目。

希望它有效!

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