该问题由 Gradle 的Maven仓库在国外访问受限引起,使用阿里云的镜像仓库地址替代解决
1.修改Flutte SDK目录下的Flutter打包配置文件flutter.gradle
一般位于flutter\packages\flutter_tools\gradle\flutter.gradle
1
buildscript {
repositories {
//google()
//mavenCentral()
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 {
/** When bumping, also update ndkVersion above, as well as the Android Gradle Plugin
* version in ../lib/src/android/gradle_utils.dart.
*/
classpath 'com.android.tools.build:gradle:7.3.0'
}
}
2
//此处可以配置环境变量FLUTTER_STORAGE_BASE_URL为 https://storage.flutter-io.cn来达到相同的效果
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";
//private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
3
@Override
void apply(Project project) {
.....
// Configure the Maven repository.
String hostedRepository = System.env.FLUTTER_STORAGE_BASE_URL ?: DEFAULT_MAVEN_HOST
String repository = useLocalEngine()
? project.property('local-engine-repo')
: "$hostedRepository/download.flutter.io"
rootProject.allprojects {
repositories {
maven {
url repository
}
//追加下面的内容
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' }
}
}
.....
}
2.修改Flutte SDK目录下的resolve_dependencies.gradle
一般位于flutter\packages\flutter_tools\gradle\resolve_dependencies.gradle
...
//此处可以配置环境变量FLUTTER_STORAGE_BASE_URL为 https://storage.flutter-io.cn来达到相同的效果
String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.flutter-io.cn"
//String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.googleapis.com"
repositories {
//google()
//mavenCentral()
maven {
url "$storageUrl/download.flutter.io"
}
//追加下面
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' }
}
...
3.修改Flutter项目下的android下的build.gradle
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
//google()
//mavenCentral()
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:8.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
//google()
//mavenCentral()
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' }
}
}
.....
标签:assembleDebug,task,aliyun,repository,url,Gradle,maven,https,com
From: https://www.cnblogs.com/fanqisoft/p/17528904.html