我的Github:   Github

Flutter gradle采坑

前些日子google推出Flutter1.9版本支持web果断升级

在运行flutter时发现错误,错误提示为

复制代码
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process exited abnormally:

> Configure project :app

Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/haishun/project/phoneapp/myapp/android/app/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not resolve com.android.tools.build:gradle:3.5.0.
     Required by:
         unspecified:unspecified:unspecified
      > Could not resolve com.android.tools.build:gradle:3.5.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom'.
               > dl.google.com:443 failed to respond
      > Could not resolve com.android.tools.build:gradle:3.5.0.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom'.
               > jcenter.bintray.com:443 failed to respond

* 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 0s
  Command: /Users/haishun/project/phoneapp/myapp/android/gradlew app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.
复制代码

可以看出会连接google服务,因GWF原因我们修改为阿里云

复制代码
buildscript {
    repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
}
复制代码

修改以上代码,再次运行flutter run

复制代码
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.2.1.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.2.1.
         > Could not get resource 'https://maven.aliyun.com/repository/google/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
            > Could not HEAD 'https://maven.aliyun.com/repository/google/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
               > Connect to 127.0.0.1:1080 [/127.0.0.1] failed: Connection refused (Connection refused)
      > Could not resolve com.android.tools.build:gradle:3.2.1.
         > Could not get resource 'https://maven.aliyun.com/repository/jcenter/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
            > Could not HEAD 'https://maven.aliyun.com/repository/jcenter/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
               > Connect to 127.0.0.1:1080 [/127.0.0.1] failed: Connection refused (Connection refused)
      > Could not resolve com.android.tools.build:gradle:3.2.1.
         > Could not get resource 'http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
            > Could not HEAD 'http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
               > Connect to 127.0.0.1:1080 [/127.0.0.1] failed: Connection refused (Connection refused)
复制代码

再度提示我们同样的错误,127.0.0.1:1080,好像没有设置这个代理,去项目目录下android/gradle.properties查看该文件发现并无代理设置

同样打开全局配置文件,Windows在个人文档目录下,Mac/*nix在用户目录下.gradle/gradle.properties打开发现

 存在代理配置将其删除即可

 

posted @   寂夜云  阅读(6610)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示