如何修复 flutter 项目中的 gradle 错误

How to fix gradle error in flutter project

提问人:Mike Osborn 提问时间:9/25/2021 更新时间:4/15/2022 访问量:10032

问:

我在运行 flutter 项目时收到此 gradle 错误:

我正在使用 github 中的代码进行 flutter pdf 视图,并且还使用 firebase。

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.4+3/lib/src/path_provider_windows_real.dart:126:25: Error: The getter 'addressOf' isn't defined for the class 'GUID'.
 - 'GUID' is from 'package:win32/src/structs.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
          knownFolderID.addressOf, KF_FLAG_DEFAULT, NULL, pathPtrPtr);

                        ^^^^^^^^^

      ^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3/lib/src/utf16.dart:16:7: Error: Struct 'Utf16' is empty. Empty structs are undefined behavior.

class Utf16 extends Struct {
      ^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3/lib/src/allocation.dart:47:33: Error: Expected type 'T' to be a valid and instantiated subtype of 'NativeType'.
  final int totalSize = count * sizeOf<T>();
                                ^

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* 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 28s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

请帮帮我,我多次遇到这些 gradle 错误。 谢谢

Firebase Gradle 构建 gradle-plugin

评论

0赞 Mike Osborn 9/30/2021
@George错了,旧文件有问题,我删除了它们,现在它工作正常
0赞 M Karimi 11/28/2021
查看 stackoverflow.com/a/70140796/11675817

答:

6赞 Mike Osborn 9/30/2021 #1

删除 .idea 文件夹、build 文件夹和 pubspec.lock 文件,然后它就可以正常工作了。