首次运行Flutter应用失败:无法下载bcprov-jdk15on.jar依赖
Hey there! I’ve dealt with this exact Gradle download error when setting up new Flutter projects before—super frustrating, but totally fixable. Let’s walk through the solutions step by step:
Common Causes
The root issue here is that JCenter (the repository Gradle is trying to pull the jar from) has been archived and is no longer maintained since 2021. Many old packages hosted there are either unavailable or slow to download, especially with network restrictions.
Step-by-Step Fixes
1. Check Your Network Connection
First, rule out basic network issues:
- Try switching to a stable network (like a mobile hotspot if you’re on a restricted work/school network)
- Ensure you can access external Maven repositories without proxy blocks
2. Replace JCenter with Active Repositories
Since JCenter is no longer reliable, update your Gradle config to use maintained repositories like Maven Central or domestic mirrors:
- Open your project’s
android/build.gradlefile - Find the
repositoriesblocks (both inbuildscriptandallprojects) and replacejcenter()with:repositories { google() mavenCentral() // Optional: Add Alibaba Maven mirror for faster downloads in regions with slow global access maven { url 'https://maven.aliyun.com/repository/public' } } - Do the same check in
android/app/build.gradleif there’s arepositoriesblock present
3. Clean Gradle Cache & Rebuild
Corrupted cache files often cause download failures. Let’s wipe them:
- Run this command in your project root:
flutter clean - Delete the
android/.gradlefolder manually (it will regenerate automatically) - Run
flutter pub getto refresh dependencies, then try launching your app again
4. Manual Jar Import (Last Resort)
If the above steps don’t work, you can manually add the jar file:
- Download
bcprov-jdk15on-1.56.jar(search for it on Maven Central to find a valid source) - Create a
libsfolder inandroid/app/and place the jar inside it - Add this line to the
dependenciesblock inandroid/app/build.gradle:implementation files('libs/bcprov-jdk15on-1.56.jar') - Rebuild your project
内容的提问来源于stack exchange,提问作者SouRav GhoSh

