android - Unresolved reference : ext when convert gradle to gradle. kts

标签 android gradle gradle-kotlin-dsl

默认情况下,当我从 Android Studio 创建一个撰写应用程序时,它会给我 ext在我的根项目中如下 build.gradle .

buildscript {
    ext {
        compose_version = '1.0.0'
    }
    repositories {
        google()
        mavenCentral()
    }
}
当我将其更改为 build.gradle.kts ,它会提示
Unresolved reference: ext
Unresolved reference: compose_version
Too many characters in a character literal ''1.0.0''
我该如何解决这个问题?

最佳答案

我用

buildscript {
    extra.apply{
        set("compose_version", "1.0.0")
    }
    repositories {
        google()
        mavenCentral()
    }
从其他 gradle 访问它文件,我需要明确设置为一个变量
val composeVersion = rootProject.extra.get("compose_version") as String
然后我可以像使用它一样
composeOptions {
    kotlinCompilerExtensionVersion = composeVersion
}
dependencies {
   implementation ("androidx.compose.ui:ui:$composeVersion")
}

关于android - Unresolved reference : ext when convert gradle to gradle. kts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69323109/

相关文章:

android - 尝试将 Android Gradle 项目从 Groovy 迁移到 Kotlin 时出现 CacheOpenException

Android独立服务怎么来的?

android - 如何修复Android Studio Gradle

android - android中的滑动抽屉布局问题

gradle - 如何在 Gradle 中并行运行特定任务

android - 需要 Gradle 版本 2.2。当前版本是 4.4 错误

gradle - 如何使用 Gradle 和 Kotlin DSL 创建额外的 Kotlin SourceSet

android - 有没有办法让 gradle task lintRelease 在为特定模块执行时什么都不做?

Android Intent-filter mimetype 和主机/方案

android - 加入两个表并获取 Cursorloader 的游标