解决Flutter启动一直卡在 Running Gradle task ‘assembleDebug‘...

前言

新建了一个Flutter工程后,Run APP 却一直卡在了Running Gradle task 'assembleDebug'... 这里。百度查询原因是因为 Gradle 的 Maven 仓库在国外, 因此需要使用阿里云的镜像地址。

1、修改项目中android/build.gradle文件

将 buildscript.repositories 下面的

Dart 复制代码
//google()
//mavenCentral()

注释掉,改成

maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/google'
}
maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
   allowInsecureProtocol = true
   url 'http://maven.aliyun.com/nexus/content/groups/public'
}

allprojects.repositories 同上修改

使用"阿里云"仓库为下载源,可能会报错(gradle的仓库地址不安全警告的错误),因为配置了除 maven 中央仓库之外的其他不安全的仓库(一些国内的镜像仓库,如"阿里云"镜像仓库也是不安全的),如下所示:

A problem occurred configuring root project 'Packer'.

> Could not resolve all dependencies for configuration ':classpath'.

> Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://maven.aliyun.com/nexus/content/groups/public/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.0.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

* Try:

Run with --info or --debug option to get more log output. Run with --scan to get full insights.

解决方法:只需要在App项目工程的 build.gradle 中,使用 allowInsecureProtocol 属性(允许gradle使用"不安全"的仓库并且不报警告信息)即可

Dart 复制代码
allowInsecureProtocol = true

2、修改 Flutter SDK 中packages\flutter_tools\gradle\flutter.gradle文件

将 buildscript.repositories 下面的

Dart 复制代码
//google()
//mavenCentral()

注释掉,改成

maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/google'
}
maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
   allowInsecureProtocol = true
   url 'http://maven.aliyun.com/nexus/content/groups/public'
}

将 DEFAULT_MAVEN_HOST 值修改成 "https://storage.flutter-io.cn";

Dart 复制代码
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";
相关推荐
Zender Han10 小时前
Flutter 视频播放器——flick_video_player 介绍与使用
android·flutter·ios·音视频
恋猫de小郭14 小时前
Flutter Riverpod 3.0 发布,大规模重构下的全新状态管理框架
android·前端·flutter
RaidenLiu16 小时前
Riverpod 3:重建控制的实践与性能优化指南
前端·flutter
蒋星熠1 天前
Flutter跨平台工程实践与原理透视:从渲染引擎到高质产物
开发语言·python·算法·flutter·设计模式·性能优化·硬件工程
卢叁1 天前
Flutter之自定义TabIndicator
前端·flutter
萧雾宇2 天前
Android Compose打造仿现实逼真的烟花特效
android·flutter·kotlin
拜无忧2 天前
【教程】flutter常用知识点总结-针对小白
android·flutter·android studio
拜无忧2 天前
【教程】Flutter 高性能项目架构创建指南:从入门到高性能架构
android·flutter·android studio
醉过才知酒浓2 天前
flutter 拦截返回按钮的方法(WillPopScope or PopScope)
flutter
傅里叶2 天前
sudo启动Flutter程序AMD初始化失败
linux·flutter