Gradle“清单需要占位符替换"错误但 manifestP

时间:2023-02-12
本文介绍了Gradle“清单需要占位符替换"错误但 manifestPlaceholders 提供了一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 build.gradle android 扩展的 AndroidManifest.xml 文件中执行替换,但出现此错误:

I'm trying to perform substitution within the AndroidManifest.xml file from the build.gradle android extension but am getting this error:

AndroidManifest.xml:89:16 Error:
    Attribute uses-library#com.company.platform.${encoding}@name at AndroidManifest.xml:89:16 requires a placeholder substitution but no value for <encoding> is provided.
/Users/Company/Desktop/Checkout/android/Project/app/src/main/AndroidManifest.xml:0:0 Error:
    Validation failed, exiting
:app:processDebugManifest FAILED

这是清单文件的片段:

...
     </receiver>
   <uses-library android:name="com.company.platform.${encoding}" />
</application>
...

这是 build.gradle 的片段:

And this is a snipped of the build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "com.company.app"
        minSdkVersion 23
        targetSdkVersion 23
        versionName cityVersion
        setProperty("archivesBaseName", "City_$versionName")
        manifestPlaceholders = [encoding: "some value"]
        manifestPlaceholders = [version: cityVersion]
    }

我也尝试在 buildTypes 中添加 manifestPlaceholders,即

I've also tried adding the manifestPlaceholders in the buildTypes i.e.

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
   }
    debug {
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
    }

}

但我仍然遇到同样的错误.

But I still get the same error.

当 manifestPlaceholders 中提供了占位符替换时,为什么会出现需要替换占位符的错误?

Why is there an error about it requiring a placeholder substitution when one is provided for in the manifestPlaceholders?

推荐答案

你只需要添加到数组中.你正在替换它.这样做:

You need to just add to the array. You are replacing it. Do this:

manifestPlaceholders = [encoding: "some value", version: cityVersion]

通过为相同的风格/构建类型声明 manifestPlaceholders 两次,您将替换前一个.替换前一个后,您的构建失败,因为该属性不再存在.

By declaring manifestPlaceholders twice for the same flavor/build type, your are replacing the previous one. After the previous one got replaced, your build failed because the property no longer exists.

这篇关于Gradle“清单需要占位符替换"错误但 manifestPlaceholders 提供了一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:清单合并失败:uses-sdk:minSdkVersion 1 不能小于版本 下一篇:Gradle 排除或添加硬包含在库 classes.jar 中的 JAR 文

相关文章

最新文章