flutter 卡在Running Gradle task ‘assembleDebug’…

Android项目运行时出错

卡在Initializing gradle…

运行时会卡在Initializing gradle..., 此时因为Android项目会用到Gradle, 如果没有FQ,下载速度会非常慢, 此时我们可以在项目中的android/gradle/wrapper/gradle-wrapper.properties中查看gradle版本号以及地址, 我们可以手动下载然后解压到~/.gradle/wrapper/dists/中。

卡在Running ‘gradle assembleDebug’

运行时会卡在Running 'gradle assembleDebug, 因为Gradle的Maven仓库在国外, 可以使用阿里云的镜像地址。

  1. * 修改项目中`android/build.gradle`文件
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
26
27
28
29
30
31
32
33
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.2.1’
}
}
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‘ }
}
}
rootProject.buildDir = ‘../build’
subprojects {
project.buildDir = “${rootProject.buildDir}/${project.name}”
}
subprojects {
project.evaluationDependsOn(‘:app’)
}
task clean(type: Delete) {
delete rootProject.buildDir
}
  1. * 修改Flutter的配置文件, 该文件在`Flutter安装目录/packages/flutter_tools/gradle/flutter.gradle`
1
2
3
4
5
6
7
8
9
10
11
12
13
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.2.1’
}
}

注:如果网络有点慢的话,可能会出现:
C:\Users\zhangsw.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7-all.zip
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download…
这样的错误提示,打开提示中的路径可能看到目录中没有成功下载到gradle-6.7-all.zip,等一会看看也许就能下载成功,或是打开android/gradle下面的gradle-wrapper.properties,找到“distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip”手动下载;