Android studio用simulator运行flutter项目时候,一直卡在Running Gradle task 'assembleDebug'...
这是因为Android studio运行项目时需要请求部分资源,而请求外网资源,需要翻墙或者换源
解决方法:更换阿里源
1.1 修改Flutter SDK安装目录下的文件:flutter/packages/flutter_tools/gradle/flutter.gradle(如果找不到,那就修改这个flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy)
repositories {
// google()
// mavenCentral()
maven { url '[https://maven.aliyun.com/repository/google'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fgoogle%27) }
maven { url '[https://maven.aliyun.com/repository/jcenter'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fjcenter%27) }
maven { url '[https://maven.aliyun.com/nexus/content/groups/public'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Fnexus%2Fcontent%2Fgroups%2Fpublic%27) }
}
class FlutterPlugin implements Plugin<Project> {
// private static final String DEFAULT_MAVEN_HOST = "[https://storage.googleapis.com](https://links.jianshu.com/go?to=https%3A%2F%2Fstorage.googleapis.com)";
private static final String DEFAULT_MAVEN_HOST = "[https://storage.flutter-io.cn](https://links.jianshu.com/go?to=https%3A%2F%2Fstorage.flutter-io.cn)";
...}
1.2. 修改Flutter SDK安装目录下的文件:flutter\packages\flutter_tools\gradle/resolve_dependencies.gradle
repositories {
// google()
// mavenCentral()
maven { url '[https://maven.aliyun.com/repository/google'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fgoogle%27) }
maven { url '[https://maven.aliyun.com/repository/jcenter'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fjcenter%27) }
maven { url '[https://maven.aliyun.com/nexus/content/groups/public'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Fnexus%2Fcontent%2Fgroups%2Fpublic%27) }
maven {
// url "$storageUrl/download.flutter.io"
url "[https://storage.flutter-io.cn/download.flutter.io](https://links.jianshu.com/go?to=https%3A%2F%2Fstorage.flutter-io.cn%2Fdownload.flutter.io)"
}
}
2.1修改Flutter项目目录的文件:android\build.gradle
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
// google()
// mavenCentral()
maven { url '[https://maven.aliyun.com/repository/google'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fgoogle%27) }
maven { url '[https://maven.aliyun.com/repository/jcenter'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fjcenter%27) }
maven { url '[https://maven.aliyun.com/nexus/content/groups/public'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Fnexus%2Fcontent%2Fgroups%2Fpublic%27) }
}
...
allprojects {
repositories {
// google()
// mavenCentral()
maven { url '[https://maven.aliyun.com/repository/google'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fgoogle%27) }
maven { url '[https://maven.aliyun.com/repository/jcenter'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fjcenter%27) }
maven { url '[https://maven.aliyun.com/nexus/content/groups/public'](https://links.jianshu.com/go?to=https%3A%2F%2Fmaven.aliyun.com%2Fnexus%2Fcontent%2Fgroups%2Fpublic%27) }
}
}