Flutter
版本:3.22.3
该解决办法源自
1. 修改Flutter SDK
目录下的Flutter
打包配置文件flutter.groovy
该文件一般位于
flutter\packages\flutter_tools\gradle\src\main\groovy\
Step 1
// This buildscript block supplies dependencies for this file's own import
// declarations above. It exists solely for compatibility with projects that
// have not migrated to declaratively apply the Flutter Gradle Plugin;
// for those that have, FGP's `build.gradle.kts` takes care of this.
buildscript {
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/public' }
}
dependencies {
// When bumping, also update:
// * ndkVersion in FlutterExtension in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
// * AGP version in the buildscript block in packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts
// * AGP version constants in packages/flutter_tools/lib/src/android/gradle_utils.dart
// * AGP version in dependencies block in packages/flutter_tools/gradle/build.gradle.kts
classpath("com.android.tools.build:gradle:7.3.0") //你自己的gradle版本
}
}
Step 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"
Step 3
//追加下面的内容
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/public' }
2. 修改Flutter SDK
目录下的resolve_dependencies.gradle
该文件一般位于
flutter\packages\flutter_tools\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"
String engineRealm = Paths.get(flutterRoot.absolutePath, "bin", "internal", "engine.realm")
.toFile().text.trim()
if (engineRealm) {
engineRealm = engineRealm + "/"
}
repositories {
// google()
// mavenCentral()
maven {
url "$storageUrl/${engineRealm}download.flutter.io"
}
//追加下面
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/public' }
}
3. 修改Flutter项目下的android下的build.gradle
allprojects {
repositories {
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/public' }
}
}