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

Flutter构建失败求助:Gradle任务assembleDebug因依赖包下载失败(主机解析问题)报错

Fix for Flutter Gradle Build Failure (Unknown Host Errors)

Hey there, I’ve dealt with this exact problem a few times—your build is failing because Gradle can’t connect to the required Maven repositories (the "unknown host" messages for dl.google.com and jcenter.bintray.com are the dead giveaway). Here’s a step-by-step breakdown of how to fix it:

1. Verify Your Network Connectivity

First, make sure your internet is working properly and you can access the problematic domains. Open a browser and try visiting the direct URLs mentioned in the error log. If these links don’t load, you’re likely facing network restrictions (like a firewall or regional blocks) or DNS issues.

2. Configure Gradle Proxy (If You’re Behind a Proxy)

If you’re working in an environment with a proxy server, you need to tell Gradle about it. Edit the android/gradle.properties file in your Flutter project and add these lines (replace placeholders with your actual proxy details):

# HTTP proxy settings
systemProp.http.proxyHost=your_proxy_address
systemProp.http.proxyPort=your_proxy_port

# HTTPS proxy settings
systemProp.https.proxyHost=your_proxy_address
systemProp.https.proxyPort=your_proxy_port

# Add these if your proxy requires authentication
systemProp.http.proxyUser=your_proxy_username
systemProp.http.proxyPassword=your_proxy_password
systemProp.https.proxyUser=your_proxy_username
systemProp.https.proxyPassword=your_proxy_password

3. Switch to Domestic Maven Mirrors

If accessing Google’s or JCenter’s official repositories is slow or blocked, replace them with reliable domestic mirrors (like Alibaba’s). Open android/build.gradle and update the repositories sections:

Original Code:

buildscript {
    repositories {
        google()
        jcenter()
    }
    // ... other configurations
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Updated Code:

buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
    }
    // ... other configurations
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
    }
}

4. Clean Caches and Rebuild

Corrupted Gradle cache can sometimes cause unexpected issues. Run these commands to clear everything and start fresh:

flutter clean
cd android
./gradlew clean
./gradlew assembleDebug
cd ..
flutter run

5. Fix DNS Resolution Issues

If the problem is related to DNS, try switching your DNS server to a public one:

  • Google DNS: 8.8.8.8 or 8.8.4.4
  • Domestic DNS: 114.114.114.114

Adjust your network settings to use one of these, then try building your project again.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 05:29:11