我的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 @ 2019-09-17 10:20  寂夜云  阅读(6578)  评论(0编辑  收藏  举报