1、问题:用安卓模拟器打开flutter项目时候,一直卡在Running Gradle task 'assembleDebug'...
2、原因:这是因为android studio运行项目时需要请求部分资源,而请求外网资源,你懂的...
3、解决:解决方法:1、翻*墙 。2换源
我采用的方法是换阿里源
注意:public路径是http的,会报错,要用https
错误:maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
正确:maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
修改Flutter安装目录下的文件:flutter\packages\flutter_tools\gradle/flutter.gradle
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
}
class FlutterPlugin implements Plugin<Project> {
// private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";
...}
修改Flutter安装目录下的文件:flutter\packages\flutter_tools\gradle/resolve_dependencies.gradle
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
maven {
// url "$storageUrl/download.flutter.io"
url "https://storage.flutter-io.cn/download.flutter.io"
}
}
修改项目目录的文件:android\build.gradle
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
}
...
allprojects {
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
}
}