当前位置: 首页 > 知识库问答 >
问题:

无法获取未知属性“local properties”

严昀
2023-03-14

我想读取build.gradle中local.properties中定义的属性(如本文所述),因此在根build.gradle文件中有以下内容:

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

def localProperties = new Properties()
if (project.rootProject.file('local.properties').canRead()) {
    localProperties.load(project.rootProject.file("local.properties").newDataInputStream())
}

buildscript {

    ext {
        ...
    }

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$gradleVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"


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

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

在模块的build.gradle文件中,我有以下内容:

android {
    ...
    defaultConfig {
        ...
        buildConfigField "String", "TOKEN", localProperties['token']
    }
}

但同步后出现以下错误:

无法获取类型为com.android.build.gradle.internal.dsl.defaultconfig得defaultconfig得defaultconfig{name=main,...}得未知属性“local properties”.

我错在哪?如何解决这个问题?

共有1个答案

艾晋
2023-03-14

我遇到了点麻烦。变量localproperties不是内置的,而是您自己定义的。您可以添加

Properties localProperties = new Properties()
    File file = project.rootProject.file('local.properties')
    if (file.exists()) {
        localProperties.load(file.newDataInputStream())
    }

defaultConfig块中的build.gradle。

 类似资料:
  • 所以,昨天一切都很好,但现在Android Studio和我的项目抛出了这个错误: 我谷歌了很长时间,但还没有找到任何解决方案。我的项目没有任何单词“Assemble”(项目中的Ctrl+Shift+F)。 gradlew clean Build-StackTrace:

  • 我切换到gradle 7.0最近,现在不能建立我的项目罐,与错误 无法获取类型为org的配置容器的未知属性“runtime”。格雷德尔。应用程序编程接口。内部的人工制品配置。DefaultConfigurationContainer` 这是我的build.gradle:

  • 我最近一直有这个问题,因为我到处搜索,也在这里堆栈,我看到了很多不同的答案。 有人知道如何解决这个问题吗? 错误:(46,0)无法为类型为com.android.build.gradle.internal.dsl.signingconfig的SigningConfig_Endaried{name=debug,storefile=C:\users\-shahab-\desktop\master\tm

  • 当运行android时,我对本机项目做出了反应,显示了这个错误 生成文件'C:\dev\icnet\u final\android\app\Build。格拉德尔线:213 评估项目“: app”时出现问题。 无法获取类型为org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer的配置容器的未知属性“

  • 我使用的正是处理依赖项的代码片段 我使用的版本:

  • 问题内容: 如果我有这样的JSON对象: 属性的名称(这里)每次都在变化,我怎么能仅仅通过JS 获得子属性?目前我有,但是现在我怎么能得到它的孩子呢? 问题答案: 如果它始终是的第一个属性,则可以执行以下操作: