You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目Gradle构建失败,如何将仓库切换为HTTPS访问?

Fix Gradle Build Failure by Switching to HTTPS Repositories

Hey there! I’ve run into this exact issue before when network policies block HTTP access to package repositories. Since you can reach those domains via HTTPS just fine, we just need to update Gradle’s configuration to use HTTPS URLs instead of HTTP ones. Here’s how to do it step by step:

1. Update Project-Level build.gradle

First, open your Flutter project’s root directory and edit the build.gradle file (not the one inside the app folder). Look for the repositories blocks and replace all HTTP URLs with their HTTPS equivalents:

// Before
repositories {
    maven { url 'http://download.flutter.io' }
    maven { url 'http://dl.google.com/maven2' }
    jcenter()
}

// After
repositories {
    maven { url 'https://download.flutter.io' }
    google() // This uses HTTPS by default, replaces the dl.google.com repo
    mavenCentral() // Recommended over jcenter, which is no longer maintained
}

2. Update Flutter SDK’s Global Gradle Config

If your project relies on the Flutter SDK’s internal Gradle settings, you’ll need to tweak that too:

  • Navigate to your Flutter SDK installation directory, then go to flutter/packages/flutter_tools/gradle/
  • Open flutter.gradle and find the repositories section inside the buildscript block
  • Replace http://download.flutter.io with https://download.flutter.io

3. Fix Gradle Wrapper Distribution URL

Check if your Gradle wrapper is using an HTTP URL for the Gradle distribution:

  • Open gradle/wrapper/gradle-wrapper.properties in your project
  • Look for the distributionUrl line, and change http:// to https://:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
    

4. Clear Gradle Caches

Old cached HTTP resources might still cause issues, so let’s clear them:

  • Run flutter clean in your project’s root directory via command line
  • Delete the Gradle cache folder (Windows path: C:\Users\[Your Username]\.gradle\caches)
  • Or run gradlew cleanBuildCache in your project’s root to clear build-specific caches

After making these changes, restart Android Studio, click "Sync Project with Gradle Files", and try running your Flutter app again. This should resolve the HTTP access errors since all repository requests will now use HTTPS.

内容的提问来源于stack exchange,提问作者Zionnite

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:48:15