gpt4 book ai didi

java - 无法为 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象设置未知属性 'nav_version'

转载 作者:行者123 更新时间:2023-12-02 08:59:53 25 4
gpt4 key购买 nike

我试图添加导航依赖项以在我的项目中使用导航图,并且 android studio 抛出了此错误。

这是我的项目 Gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
nav_version = "2.3.0-alpha01" //extra property, used like variables
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

如您所见,我添加了 $nav_version 依赖项和 nav_version 变量。但是,android studio 抛出“无法为 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象设置未知属性‘nav_version’”错误。我想知道这是否与 Gradle 版本或我的 Kotlin 版本有关。我尝试清理并重新构建我的项目,但没有成功。想知道有没有人遇到过类似的情况。

最佳答案

它应该是应用程序级别 build.gradle 的一部分。

类似于

dependencies {
def nav_version = "2.3.0-alpha01"

// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

// Dynamic Feature Module Support
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
}

& 顶级/项目级别 gradle

buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.3.0-alpha01"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}

或者将其放置为 ${nav_version}

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:${nav_version}"

或者

buildScript {
ext {
nav_version = "2.3.0-alpha01"
kotlin_version = "1.3.50"
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:${nav_version}"
}
}

引用 https://developer.android.com/guide/navigation/navigation-getting-started

关于java - 无法为 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象设置未知属性 'nav_version',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60250971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com