androidgradle_1">1、在android的模块中进行gradle环境配置
①在 gradle-wrapper.properties文件中将url配置为阿里云镜像,因为gradle的服务器在国外,国内下载非常慢,也可在官网进行下载
gradle版本下载
gradle版本匹配
阿里云镜像gradle下载
可以通过复制链接方式让AS下载,也可以自行下载,加载本地文件
//复制链接下载
distributionUrl=https\://mirrors.aliyun.com/gradle/distributions/v8.7.0/gradle-8.7-bin.zip
//加载本地文件
distributionUrl=file:///D:/gradle/gradle-8.3-all.zip
②配置build.gradle和settings.gradle,将其修改为镜像链接
google() 对应的是
maven { url ‘https://maven.aliyun.com/repository/google’ }
mavenCentral() 对应的是
maven { url ‘https://maven.aliyun.com/nexus/content/repositories/central’ }
所以在将其修改为
allprojects {repositories {maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/nexus/content/repositories/central' }maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }}
}
③ 出现的问题
(1) 仓库错误
Could not find j2objc-annotations-2.8.jar (com.google.j2objc:j2objc-annotations:2.8).
Searched in the following locations:
https://maven.aliyun.com/repository/jcenter/com/google/j2objc/j2objc-annotations/2.8/j2objc-annotations-2.8.jar
maven { url ‘https://maven.aliyun.com/repository/jcenter’ }对应的是jcenter(), jCenter 仓库已经在 2021 年被宣布弃用,并在 2022 年初停止服务。因此,从 jCenter 下载依赖可能不再可行
androidapplication_version_860__42">(2) AGP 版本不对,即id “com.android.application” version “8.6.0” 不匹配,
android-35所需的最低版本为 8.6.0**
failed to load include path C:\Users\10557\AppData\Local\Android\sdk\platforms\android-35\android.jar
flutter_sdkgradle_47">2、在flutter sdk中配置gradle
在[flutter存放的位置] \flutter\packages\flutter_tools\gradle 下的flutter.gradle文件添加
buildscript{repositories {maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/nexus/content/repositories/central' }maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }gradlePluginPortal()}
}
3、推荐使用命令gradlew进行build可以看见进度
清空: ./gradlew clear
创建: ./gradlew build
第一次创建的时间较长,使用AS进行开发flutter,没有build的图标(大象图标),最好使用命令进行build。