启动Flutter应用时遇Could not GET jitpack.io资源错误求助
问题核心
构建Flutter应用时,Gradle无法获取https://jitpack.io/me/carda/androidcore/0.7.2/androidcore-0.7.2.aar,服务器返回521状态码。这是Jitpack服务器端的连接故障(Cloudflare 521错误表示源服务器拒绝了Cloudflare的连接请求),和你的本地环境无关(此前代码运行正常也验证了这一点)。
解决方案
- 等待服务器恢复:521属于服务端临时故障,暂停构建10-30分钟后,重新执行
flutter run。 - 清理Gradle缓存:
- 执行命令:
flutter clean - 手动删除项目根目录下
android/.gradle文件夹,再重新构建。
- 执行命令:
- 更换依赖版本:如果该版本长期无法访问,去对应库的代码仓库查看可用版本,修改项目中的依赖配置(
pubspec.yaml或Android模块的build.gradle),替换为其他稳定版本。 - 本地导入依赖:若上述方法无效,可尝试将该aar文件从其他可信源下载后作为本地依赖导入:
- 将
androidcore-0.7.2.aar放到android/app/libs目录 - 在
android/app/build.gradle的dependencies块中添加:implementation files('libs/androidcore-0.7.2.aar') - 移除原来指向Jitpack的远程依赖。
- 将
补充说明
你提供的flutter doctor结果中,Visual Studio的缺失组件仅影响Windows平台开发,和当前Android构建失败无关,无需优先处理。
原错误日志
Launching lib\main.dart on SM A125F in debug mode...
Running Gradle task 'assembleDebug'...
Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
Warning: élément inattendu (URI : "", local : "extension-level"). Les éléments attendus sont <{}codename>,<{}layoutlib>,<{}api-level>
Warning: élément inattendu (URI : "", local : "base-extension"). Les éléments attendus sont <{}codename>,<{}layoutlib>,<{}api-level>
Format incorrect du paramètre -FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:mergeDebugAssets'.Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Failed to transform androidcore-0.7.2.aar (me.carda:androidcore:0.7.2) to match attributes {artifactType=android-assets, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
Could not download androidcore-0.7.2.aar (me.carda:androidcore:0.7.2)
Could not get resource 'https://jitpack.io/me/carda/androidcore/0.7.2/androidcore-0.7.2.aar'.
Could not GET 'https://jitpack.io/me/carda/androidcore/0.7.2/androidcore-0.7.2.aar'. Received status code 521 from server:
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 1m 8s
Retrying Gradle Build: #1, wait time: 100ms
[!] Gradle threw an error while downloading artifacts from the network.
本地环境检测结果
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.3.3, on Microsoft Windows [version 10.0.22621.963], locale fr-SN) Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [√] Chrome - develop for the web [!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6) X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools - If there are multiple build tool versions available, install the latest C++ CMake tools for Windows Windows 10 SDK [√] Android Studio (version 2021.3) [√] IntelliJ IDEA Ultimate Edition (version 2022.1) [√] VS Code (version 1.74.1) [√] Connected device (4 available) [√] HTTP Host Availability ! Doctor found issues in 1 category.
内容的提问来源于stack exchange,提问作者Saliou Seck

