我有一个flutter项目,一直在mac电脑上开发,现在移植到windows开发,但是启动安卓端一直gradle失败,可以尝试以下几种方法解决。
- 1.检查自己的gradle目录下gradle.properties配置文件是否有开启代理
目录一般位于用户文件夹下,如C:\Users\Administrator\.gradle\gradle.properties
,如开启代理就注释掉
- 2.环境变量配置
改成国内源,另外PUB_CACHE 要设置成和自己项目在同一个盘
PUB_HOSTED_URL https://mirrors.tuna.tsinghua.edu.cn/dart-pub
FLUTTER_STORAGE_BASE_URL https://mirrors.tuna.tsinghua.edu.cn/flutter
PUB_CACHE D:\xxx\pub
- flutter配置国内源
路径位于C:\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy
前面是你的flutter所在目录
找到buildscript 修改
- flutter配置国内源
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/flutter.groovy
// * 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'
}
}
- 4.安卓工程内配置你的gradle
自己新建一个工程,看看你的gradle是什么版本,修改成你自己的版本
工程目录下的\android\gradle\wrapper\gradle-wrapper.properties
和\android\build.gradle
其中第二个如果版本太高可以降级
- maven配置allowInsecureProtocol =true
repositories {
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'
}
// google()
// mavenCentral()
}
- clean后在pub get
flutter clean
flutter pub get