flutter Flutter 3.29.2 gradle 国内镜像配置问题

175 天前
 wulays

flutter android 的配置文件变成了 build.gradle.ktssettings.gradle.kts,如果我没理解错的话

因为下载太慢了,尝试修改为国内镜像,网上也查了很多方式发现都没有效果,有大佬知道是什么原因吗,.gradle 也重新删除过执行 flutter clean 在重新 run 也没用,flutter\packages\flutter_tools\gradle 下的两个同名配置文件也尝试改了也没效果,搞不懂了

build.gradle.kts 配置修改如下

allprojects {
    repositories {
        // 阿里云镜像
        maven { url = uri("https://maven.aliyun.com/repository/releases") }
        maven { url = uri("https://maven.aliyun.com/repository/jcenter") }
        maven { url = uri("https://maven.aliyun.com/repository/google") }
        maven { url = uri("https://maven.aliyun.com/repository/central") }
        maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { url = uri("https://maven.aliyun.com/repository/public") }
        
        google()
        mavenCentral()
    }
}

val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}

settings.gradle.kts 配置修改如下

pluginManagement {
    val flutterSdkPath = run {
        val properties = java.util.Properties()
        file("local.properties").inputStream().use { properties.load(it) }
        val flutterSdkPath = properties.getProperty("flutter.sdk")
        require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
        flutterSdkPath
    }

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        // 阿里云镜像
        maven { url = uri("https://maven.aliyun.com/repository/releases") }
        maven { url = uri("https://maven.aliyun.com/repository/jcenter") }
        maven { url = uri("https://maven.aliyun.com/repository/google") }
        maven { url = uri("https://maven.aliyun.com/repository/central") }
        maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { url = uri("https://maven.aliyun.com/repository/public") }

        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        // 阿里云镜像
        maven { url = uri("https://maven.aliyun.com/repository/releases") }
        maven { url = uri("https://maven.aliyun.com/repository/jcenter") }
        maven { url = uri("https://maven.aliyun.com/repository/google") }
        maven { url = uri("https://maven.aliyun.com/repository/central") }
        maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { url = uri("https://maven.aliyun.com/repository/public") }
        
        google()
        mavenCentral()
    }
}


plugins {
    id("dev.flutter.flutter-plugin-loader") version "1.0.0"
    id("com.android.application") version "8.7.0" apply false
    id("org.jetbrains.kotlin.android") version "1.8.22" apply false
}

include(":app")

flutter run -v 部分日志如下

[+1197 ms] Starting Build
[ +299 ms] Generating C:\Users\Admin\.gradle\caches\8.10.2\generated-gradle-jars\gradle-api-8.10.2.jar
[+13400 ms] Cannot use Kotlin build script compile avoidance with C:\Users\Admin\.gradle\caches\8.10.2\generated-gradle-jars\gradle-api-8.10.2.jar:
class org/gradle/internal/extensions/stdlib/AutoCloseableExtensionsKt: inline fun useToRun(): compile avoidance is not supported with public inline
functions
[+2200 ms] Cannot use Kotlin build script compile avoidance with
C:\Users\Admin\.gradle\wrapper\dists\gradle-8.10.2-all\ezxzryhqdbf6stsda8vkgso9x\gradle-8.10.2\lib\gradle-kotlin-dsl-extensions-8.10.2.jar: class
org/gradle/kotlin/dsl/GradleApiKotlinDslExtensions_1cbh1oqkvm762j10e96dawuh5Kt: inline fun domainObjectContainer(): compile avoidance is not
supported with public inline functions
[   +1 ms] Cannot use Kotlin build script compile avoidance with
C:\Users\Admin\.gradle\wrapper\dists\gradle-8.10.2-all\ezxzryhqdbf6stsda8vkgso9x\gradle-8.10.2\lib\gradle-kotlin-dsl-8.10.2.jar: class
org/gradle/kotlin/dsl/ArtifactHandlerScope: inline fun invoke(): compile avoidance is not supported with public inline functions
[  +98 ms] Caching disabled for Kotlin DSL script compilation (Settings/TopLevel/stage1) because:
[        ]   Build cache is disabled
[+6999 ms] Now considering [D:\App\Env\flutter\packages\flutter_tools\gradle, D:\Tmp\flutter_demo\android] as hierarchies to watch
[  +99 ms] Caching disabled for Kotlin DSL script compilation (Settings/TopLevel/stage1) because:
[   +1 ms]   Build cache is disabled
[+3001 ms] > Configure project :gradle
[        ] Evaluating project ':gradle' using build file 'D:\App\Env\flutter\packages\flutter_tools\gradle\build.gradle.kts'.
[        ] Caching disabled for Kotlin DSL plugin specs accessors for classpath 'b27a162d178d306ba8d9ec2b2a37ae76' because:
[        ]   Build cache is disabled
[        ] Caching disabled for Kotlin DSL script compilation (Project/TopLevel/stage1) because:
[   +1 ms]   Build cache is disabled
[ +893 ms] Downloading
https://plugins.gradle.org/m2/org/gradle/kotlin/kotlin-dsl/org.gradle.kotlin.kotlin-dsl.gradle.plugin/4.5.0/org.gradle.kotlin.kotlin-dsl.gradle.plugi
n-4.5.0.pom to C:\Users\Admin\.gradle\.tmp\gradle_download13467401216642644442bin
[ +601 ms] Resource missing. [HTTP HEAD:
https://plugins.gradle.org/m2/org/gradle/kotlin/kotlin-dsl/org.gradle.kotlin.kotlin-dsl.gradle.plugin/4.5.0/org.gradle.kotlin.kotlin-dsl.gradle.plugi
n-4.5.0.jar]
1614 次点击
所在节点    程序员
8 条回复
liu731
175 天前
终端挂个代理就好( Clash 增强模式)
yatoooon
175 天前
1.开代理
2.换个网
3.把 gradle 换成之前的版本
4.不要使用 flutter 最新版 使用上一个版本


排名不分先后
Rust2015
175 天前
好像 build.gradle.kts 的阿里源跟以前的 build.gradle 不同,但是我感觉你没有写错呀

能否尝试一下 flutter create .
zoharSoul
175 天前
别改 挂代理
zeromake
175 天前
gradle 一共有三个地方要代理
- 下 gradle (./gradle/wrapper/gradle-wrapper.properties)
- 下 gradle 插件(settings.gradle.kts -> pluginManagement.repositories)
- 下项目依赖(settings.gradle.kts -> dependencyResolutionManagement.repositories)
然后都换了阿里会爆错,因为阿里的 mavenCentral 和 google 有些依赖不更新太老了……
最后只有一条出路安心挂代理
wulays
174 天前
@Rust2015 重新创建项目吗,项目已经重新创建过很多次了,没有效果,看来只能走代理了
wulays
174 天前
@zeromake 好吧,谢谢了,那还是走代理吧,好奇国内没有新的镜像了吗,网上查都是阿里的
Rust2015
174 天前
@wulays 你先要删除 Android 和 ios 目录,在创建

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1119887

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX