Gradle“清单需要占位符替换"错误但 manifestPlaceholders 提供了一个值

Gradle quot;manifest requires a placeholder substitutionquot; error but manifestPlaceholders supplies a value(Gradle“清单需要占位符替换错误但 manifestPlaceholders 提供了一个值)
本文介绍了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 提供了一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)