V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
wulays
V2EX  ›  程序员

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

  •  
  •   wulays · 1 天前 · 599 次点击

    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]
    
    8 条回复    2025-03-21 17:19:01 +08:00
    liu731
        1
    liu731  
       1 天前
    终端挂个代理就好( Clash 增强模式)
    yatoooon
        2
    yatoooon  
       1 天前
    1.开代理
    2.换个网
    3.把 gradle 换成之前的版本
    4.不要使用 flutter 最新版 使用上一个版本


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

    能否尝试一下 flutter create .
    zoharSoul
        4
    zoharSoul  
       1 天前
    别改 挂代理
    zeromake
        5
    zeromake  
       1 天前   ❤️ 1
    gradle 一共有三个地方要代理
    - 下 gradle (./gradle/wrapper/gradle-wrapper.properties)
    - 下 gradle 插件(settings.gradle.kts -> pluginManagement.repositories)
    - 下项目依赖(settings.gradle.kts -> dependencyResolutionManagement.repositories)
    然后都换了阿里会爆错,因为阿里的 mavenCentral 和 google 有些依赖不更新太老了……
    最后只有一条出路安心挂代理
    wulays
        6
    wulays  
    OP
       19 小时 37 分钟前
    @Rust2015 重新创建项目吗,项目已经重新创建过很多次了,没有效果,看来只能走代理了
    wulays
        7
    wulays  
    OP
       19 小时 35 分钟前
    @zeromake 好吧,谢谢了,那还是走代理吧,好奇国内没有新的镜像了吗,网上查都是阿里的
    Rust2015
        8
    Rust2015  
       11 小时 50 分钟前
    @wulays 你先要删除 Android 和 ios 目录,在创建
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   910 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 21:09 · PVG 05:09 · LAX 14:09 · JFK 17:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.