[Flutter FAQs] Flutter App problems at running Gradle task

FAQs about Running Gradle task

This article is about FAQs on running Gradle task.

Running Gradle task ‘assembleDebug’

The main reason for this problem is that you cannot access the Google network smoothly. You can manually change to select other available agents, such as Aliyun (AliCloud) / Alibaba Cloud.

build.gradle

First, modify your project build.gradle file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// build.gradle

buildscript {
ext.kotlin\_version = '1.3.50'
repositories {
// 这里做了修改,使用国内阿里的代理
// google()
// jcenter() maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin\_version"
}
}

allprojects {
repositories {
//修改的地方
//google()
//jcenter() maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}}

flutter.gradle

Then, modify your Flutter SDK flutter.gradle file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// ${FLUTTER_SDK}/packages\flutter_tools\gradle\flutter.gradle

buildscript {
repositories {
// 这里做了修改,使用国内阿里的代理
// google()
// jcenter()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}

Finaly, run your Flutter App.

Could not download

1
2
3
4
5
6
7
* What went wrong:
A problem occurred configuring project ':fluwx'.
> Could not resolve all artifacts for configuration ':fluwx:classpath'.
> Could not download builder-model.jar (com.android.tools.build:builder-model:4.0.1)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/4.0.1/builder-model-4.0.1.jar'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/4.0.1/builder-model-4.0.1.jar'.
> Read timed out

This problem may be caused by network instability, it should be revolved after re-run multiple times.

References

[1] Android Studio 运行flutter卡在: Running Gradle task ‘assembleDebug’… - https://juejin.cn/post/6844904142511538184

[2] 仓库服务 - https://maven.aliyun.com/mvn/guide