初学Flutter,第一运行项目时出现Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2)这个错,百度了一圈,有幸有遇到的大牛,共享了此解决办法,为了以后遇到同样问题,特记录;(转载链接再文章后面)
刚建好一个demo 编译运行一个demo 控制台就出现如下情况
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "/Users/rabbit/develop/android/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 '/Users/rabbit/develop/android/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: /Users/rabbit/develop/android/flutter_app/android/gradlew app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
网上找了也没有遇上合适的答案来解决它,我看到提示未找到 com.android.tools.lint:lint-gradle-api:26.1.2 但根据提示地址打开无法下载,如果能下载下来应该放在什么位置呢!
已解决:
解决方法1:修改build.gradle,注释掉jcenter(),google()。使用阿里的镜像。原因是jcenter 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' }
}
}
第二步:找到fluttersdk目录 进入如下目录
Macintosh HD ▸ 用户 ▸ rabbit ▸ 资源库 ▸ Flutter ▸ packages ▸ flutter_tools ▸ gradle
找到下 flutter.gradle文件 找如如下内容替换成和我一样的 把jcenter注释掉。
buildscript {
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'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
至此从新运行,解决掉问题。
原文地址:https://segmentfault.com/q/1010000016775662