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

Gradle“manifest需要一个占位符替换”错误,但manifestPlaceholders提供了一个值

魏君博
2023-03-14

我试图在build.gradle android扩展中的AndroidManifest.xml文件中执行替换,但遇到了以下错误:

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>
...
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 {
    release {
        minifyEnabled true
        shrinkResources true
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
   }
    debug {
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
    }

为什么在ManifestPlaceHolders中提供了一个占位符替换时,它需要一个占位符替换,这是错误的?

共有1个答案

贺浩漫
2023-03-14

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

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

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

 类似资料: