解决Flutter Could not find lint-gradle-api.jar

1. 在构建flutter开发环境的时候,android studio 报错:

* Error running Gradle:
ProcessException: Process "C:\xxx\Android\flutter_app\android\gradlew.bat" 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 'C:\xxx\Android\flutter_app\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 find lint-gradle-api.jar 
     Searched in the following locations:
         https://jcenter.bintray.com/com.android.tools.lint: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: C:\xxx\Android\flutter_app\android\gradlew.bat app:properties
 
Finished with error: Please review your Gradle project setup in the android/ folder.

2. 一通搜索后提示需要在Project的build.gradle内添加google(),如下:

buildscript {
    repositories {
        google() //在这里添加google
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
       google() //在这里添加google
    }
}

3.一顿操作之后满心欢喜的重新运行了项目,但是依旧不行,原因是google 库无法访问导致的,将以上两处替换为将阿里的镜像即可

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

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

4.可是有些小伙伴这种操作后还是不行,那怎么办呢,别急,下面还有一种解决方案,那就是修改⁨Flutter⁩下的flutter.gradle文件

1.直接找到并打开Flutter安装目录:⁨Flutter⁩ ▸ ⁨packages⁩ ▸ ⁨flutter_tools⁩ ▸ ⁨gradle⁩
找到下 flutter.gradle文件,把jcenter注释掉,然后再替换上ali的镜像包,这里直接贴出来好了,方便小伙伴直接复制粘贴

buildscript {
    repositories {
//        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'}
        //maven {
          //  url 'https://dl.google.com/dl/android/maven2'
        //}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}
以上就是解决 Could not find lint-gradle-api.jar的办法,如果对您有所帮助请点个赞,欢迎丢砖

你可能感兴趣的:(解决Flutter Could not find lint-gradle-api.jar)