欢迎光临
我们一直在努力

Android 开发问题:Using dependency catalogs requires the activation of the matching feature preview.

  • 在 Android 开发中,出现如下错误信息

Using dependency catalogs requires the activation of the matching feature preview.
See the documentation at https://docs.gradle.org/7.3.3/userguide/platforms.html#sub:central-declaration-of-dependencies

* Try:
> Run with –info or –debug option to get more log output.
> Run with –scan to get full insights.

* Exception is:
org.gradle.api.InvalidUserCodeException: Using dependency catalogs requires the activation of the matching feature preview.
See the documentation at https://docs.gradle.org/7.3.3/userguide/platforms.html#sub:central-declaration-of-dependencies
at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.create(DefaultVersionCatalogBuilderContainer.java:85)
at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.create(DefaultVersionCatalogBuilderContainer.java:46)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:56)
at org.gradle.configuration.BuildTreePreparingProjectsPreparer.lambda$generateDependenciesAccessorsAndAssignPluginVersions$0(BuildTreePreparingProjectsPreparer.java:82)
at org.gradle.internal.management.DefaultDependencyResolutionManagement.versionCatalogs(DefaultDependencyResolutionManagement.java:134)

问题原因
  • 这个错误表示,在 Gradle 7.3.3 中,依赖目录功能仍处于预览阶段,需要显式启用

  • 依赖目录是 Gradle 的一个功能,它允许在一个中心位置定义和管理项目依赖项,然后在整个项目中引用它们,例如

  • [versions]
    agp = "8.7.3"
    kotlin = "1.9.24"
    coreKtx = "1.10.1"
    junit = "4.13.2"
    junitVersion = "1.1.5"
    espressoCore = "3.5.1"
    appcompat = "1.6.1"
    material = "1.10.0"

    [libraries]
    androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
    junit = { group = "junit", name = "junit", version.ref = "junit" }
    androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
    androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
    androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
    material = { group = "com.google.android.material", name = "material", version.ref = "material" }

    [plugins]
    android-application = { id = "com.android.application", version.ref = "agp" }
    kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

    处理策略
    • 在 settings.gradle.kts 文件中显式启用

    enableFeaturePreview("VERSION_CATALOGS")

    赞(0)
    未经允许不得转载:171主机测评 » Android 开发问题:Using dependency catalogs requires the activation of the matching feature preview.
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址