所以我有一个 flutter 项目,我将 flutter_contacts 添加到我的 pobspec.yaml 并重建应用程序。几行输出错误:
Launching lib\main.dart on PHONE in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':flutter_contacts'.
> Could not resolve all files for configuration ':flutter_contacts:classpath'.
> Could not find gradle-7.4.1.jar (com.android.tools.build:gradle:7.4.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.4.1/gradle-7.4.1.jar
> Could not find gradle-settings-api-7.4.1.jar (com.android.tools.build:gradle-settings-api:7.4.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-settings-api/7.4.1/gradle-settings-api-7.4.1.jar
> Could not find lint-model-30.4.1.jar (com.android.tools.lint:lint-model:30.4.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-model/30.4.1/lint-model-30.4.1.jar
> Could not find builder-7.4.1.jar (com.android.tools.build:builder:7.4.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/7.4.1/builder-7.4.1.jar
问题是flutter无法访问dl.google.com下载需要的包。 但在终端(项目 direcorty)中 ping dl.google.com 的输出中,我们清楚地看到 dl.google.com 是可以访问的:
ping dl.google.com
Pinging dl.google.com [142.250.184.238] with 32 bytes of data:
Reply from 142.250.184.238: bytes=32 time=119ms TTL=51
Reply from 142.250.184.238: bytes=32 time=115ms TTL=51
Reply from 142.250.184.238: bytes=32 time=129ms TTL=51
Reply from 142.250.184.238: bytes=32 time=119ms TTL=51
Ping statistics for 142.250.184.238:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 115ms, Maximum = 129ms, Average = 120ms
我知道这是一个网络问题,我也遇到过类似的问题。通常他们用代理解决,但我不知道这个有什么问题。
我尝试在浏览器中打开链接,我可以访问 dl.google.com 以及错误中提到的每个路径。但我无法从 Android Studio 或终端(从项目目录)下载这些包。 这些是我尝试过的事情:
删除构建缓存解决了我的问题。
C:\Users\{USERNAME}\.gradle\caches
Android Studio -> File -> Invalidate Caches
并选择 Clearing file system cache and Local History
和 Delete embedded browser engine cache and cookies
flutter clean
在项目目录中flutter run
我需要使用这个link