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

2024-06-04 5388阅读

前言

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

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

将 buildscript.repositories 下面的

//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使用"不安全"的仓库并且不报警告信息)即可

allowInsecureProtocol = true

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

将 buildscript.repositories 下面的

//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";

private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";

    免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

    目录[+]