Flutter: Error running Gradle

Error running Gradle 错误

这个错误是在重装环境后出现的,重装并创建第一个项目后flutter run的时候爆出了这个错,* Error running Gradle:

ProcessException: Process "xxx/first_flutter_app/android/gradlew" exited abnormally:
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 'xxx/first_flutter_app/android/app/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all files for configuration 'classpath'.
   > Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar

* 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: xxx/first_flutter_app/android/gradlew app:properties

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

从这里面当时并没看出来是什么问题,但可以确定gradle出的问题,后来网上查了下发现是下载文件时候需要翻墙,否则有些文件就下载不了出现了这个问题。
解决办法有两个

  1. 第一个是翻墙这肯定是不方便的。
  2. 第二个解决办法就是使用阿里云的镜像文件。

下面介绍第二种解决办法,首先找到Android中的gradle文件,将代码改为下面格式

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 sdk中的flutter.gradle文件,具体路径为fluttersdk目录▸ ⁨packages⁩ ▸ ⁨flutter_tools⁩ ▸ ⁨gradle 这个文件的修改有两种类型
第一种:

repositories{

google()

gcenter()

}

这种就按下面方式修改

repositories{

//google()
//gcenter()

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'}
}

还有一种情况

repositories {
        jcenter()
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }

    

这种就按下面方式修改

repositories {
        //jcenter()
        // maven {
        //     url 'https://dl.google.com/dl/android/maven2'
        // }
        maven{
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven{
            url 'http://maven.aliyun.com/nexus/content/groups/public'
        }
    }

这样就可以解决这个问题了

发布了24 篇原创文章 · 获赞 5 · 访问量 3944

猜你喜欢

转载自blog.csdn.net/qq_41345281/article/details/102479496