美文网首页
解决Flutter 新建项目 Error running Gra

解决Flutter 新建项目 Error running Gra

作者: ping_平 | 来源:发表于2018-12-06 11:45 被阅读26次

初学Flutter,按照官网提示搭建完环境,新建一个first_flutter_app, 开开信心的Run,然后报错了:

Error running Gradle

* 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那里出问题。网上搜了下,发现项目的gradle 文件里面:

buildscript {
    repositories {
      // 需要翻墙下载
        google()
        jcenter()
    }

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

allprojects {
    repositories {
    // 需要翻墙下载
        google()
        jcenter()
    }
}

下载某些文件是需要翻墙才可以下载,所以我们在运行的时候会报错。修改如下:

用阿里云的镜像文件 解决无法翻墙下载的问题

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 下边的 gradle文件,
打开Flutter sdk目录,找到如下地址:

 flutter⁩ ▸ ⁨packages⁩ ▸ ⁨flutter_tools⁩ ▸ ⁨gradle

打开 flutter.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'
    }
}

这个时候在运行项目,可以正确运行了。

相关文章

网友评论

      本文标题:解决Flutter 新建项目 Error running Gra

      本文链接:https://www.haomeiwen.com/subject/nugncqtx.html