解決Flutter 新建項(xiàng)目 Error running Gradle 錯(cuò)誤

初學(xué)Flutter,按照官網(wǎng)提示搭建完環(huán)境,新建一個(gè)first_flutter_app, 開開信心的Run,然后報(bào)錯(cuò)了:

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.

看到這個(gè)錯(cuò)誤 一臉蒙蔽,都是按照操作來走的,沒啥問題,不過可以定位到 肯定是gradle那里出問題。網(wǎng)上搜了下,發(fā)現(xiàn)項(xiàng)目的gradle 文件里面:

buildscript {
    repositories {
      // 需要翻墻下載
        google()
        jcenter()
    }

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

allprojects {
    repositories {
    // 需要翻墻下載
        google()
        jcenter()
    }
}

下載某些文件是需要翻墻才可以下載,所以我們?cè)谶\(yùn)行的時(shí)候會(huì)報(bào)錯(cuò)。修改如下:

用阿里云的鏡像文件 解決無法翻墻下載的問題

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

這時(shí)候你以為修改完了嗎? 沒有還需要修改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'
    }
}

這個(gè)時(shí)候在運(yùn)行項(xiàng)目,可以正確運(yùn)行了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 用兩張圖告訴你,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 14,118評(píng)論 2 59
  • 1. 環(huán)境配置 全局安裝 vue-cli: 2. 初始化項(xiàng)目 這里使用官方的 vue-cli 初始化一個(gè) Vue ...
    Csourer閱讀 235評(píng)論 0 0
  • Word2vec實(shí)驗(yàn) 概述:實(shí)驗(yàn)測(cè)試了Google的word2vec (C版本)的源代碼,以及使用Twitter數(shù)...
    Maze_Runner閱讀 428評(píng)論 0 0
  • 不要去想一只粉紅色的大象, 保持兩分鐘時(shí)間 兩分鐘時(shí)間到 你的腦海中有什么? 一只粉紅色的大象 對(duì)不對(duì)? 最近因?yàn)?..
    牧沐harriet閱讀 953評(píng)論 8 2
  • 作為一個(gè)人,一個(gè)女人,我有很多角色。自己,妻子,媽媽,女兒,媳婦,妹妹,姐姐,外孫女,侄女、姨侄女,朋友,員工,心...
    心理咨詢師萍閱讀 624評(píng)論 4 2

友情鏈接更多精彩內(nèi)容