【问题标题】:Could not get unknown propert for object of type gradle build android studio无法获取 gradle build android studio 类型对象的未知属性
【发布时间】:2021-08-05 08:42:56
【问题描述】:

在我的 android studio 项目中,我的 gradle.build 文件看起来一模一样

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
        maven {
          url "https://maven.mozilla.org/maven2/"
        }
    }
    dependencies {

        classpath "com.android.tools.build:gradle:4.1.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
      implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"

    }
}

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "85.0.20201121092754"
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

但在运行 ./gradlew 时出现类似的错误

A problem occurred evaluating root project 'My Application'.
> Could not get unknown property 'geckoviewChannel' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

我在这里没有发现任何遗漏或错误。我在这里错过了什么。

【问题讨论】:

标签: android android-studio gradle gradlew geckoview


【解决方案1】:

项目属性

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "85.0.20201121092754"
}

在首先评估的 buildscript 块中不可见。一个潜在的解决方案是将 ext 块移动到 buildscript 块中。

【讨论】:

    【解决方案2】:

    这是另一个简单的错误,我通过在module_name/build.gradleas mentioned here 中练习个体依赖来设法解决了这个错误。我愚蠢地错误地忽略了项目根目录的 build.gradle 文件中的注释

    dependencies {
            ...
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
    

    所以我所做的就是将 build.gradle 重置为最初并在 module_name/build.gradle 中配置 geckoview。

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2020-06-15
      • 2020-01-02
      • 2020-04-15
      相关资源
      最近更新 更多