为什么 Gradle 会对 Android 中的 manifestPlaceholders 发出警告?

问题描述 投票:0回答:1

我目前正在开发一个 Android Kotlin 项目。在此项目中,我需要从 local.properties 文件中检索某些键,然后在 AndroidManifest.xml 文件中使用它们。但是,我遇到了一个问题,我收到一条警告,指出

'property 'googleMapsApiKey' does not exist'.

我尝试通过清理和重建项目来解决这个问题,但不幸的是,我没有成功。以下是有问题的代码片段:

Gradle(应用程序级别)代码:

defaultConfig {
        applicationId "com.testapp.myfirstapp"
        minSdk 23
        targetSdk 34
        versionCode 8
        versionName "1.0.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newDataInputStream())
        
        if (properties.containsKey('MAPS_API_KEY')) {
            manifestPlaceholders = [googleMapsApiKey: "${properties.getProperty('MAPS_API_KEY')}"]
        } else {
            println "Warning: MAPS_API_KEY not found in local.properties"
        }
    }

local.properties代码:

MAPS_API_KEY=APIkeysssd1201232ApiTestKeyStack

清单代码:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${googleMapsApiKey}" />
android gradle android-gradle-plugin
1个回答
0
投票

我刚刚选择了 build.grade 中存在错误的突出显示行,并应用了 IDE 中的建议(MacOS 中的选项 + Enter)如何修复它。不再有警告,该属性仍然有效。

© www.soinside.com 2019 - 2024. All rights reserved.