Solve the problem that Flutter startup is always stuck at Running Gradle task ‘assembleDebug‘...

Preface

After creating a new Flutter project, Run APP has been stuck at Running Gradle task ‘assembleDebug’... here. The reason for Baidu's query is that Gradle's Maven warehouse is abroad, so it needs to use the mirror address of Alibaba Cloud.

1. Modify the android/build.gradle file in the project

Place buildscript.repositories below

//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 Same as above modified

Using the "Alibaba Cloud" warehouse as the download source may result in an error (gradle warehouse address insecurity warning error) because other unsafe warehouses other than the maven central warehouse are configured (some domestic mirror warehouses, such as "Alibaba Cloud" mirror warehouse is also unsafe), as shown below:

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.

Solution: Just use the allowInsecureProtocol attribute in the build.gradle of the App project (allowing gradle to use "unsafe" warehouses and not reporting warning messages)

allowInsecureProtocol = true

2. Modify the packages\flutter_tools\gradle\flutter.gradle file in Flutter SDK

Place buildscript.repositories below

//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'
}

Change the DEFAULT_MAVEN_HOST value to "https://storage.flutter-io.cn";

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

Guess you like

Origin blog.csdn.net/weixin_47723549/article/details/133940987