我正在尝试从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

这是 list 文件的 fragment :
...
     </receiver>
   <uses-library android:name="com.company.platform.${encoding}" />
</application>
...

这是build.gradle的 fragment :
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,即
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
   }
    debug {
        manifestPlaceholders = [encoding: deviceEncoding]
        manifestPlaceholders = [version: cityIDVersion]
    }

}

但是我仍然遇到同样的错误。

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

最佳答案

您只需要添加到数组即可。您要替换它。做这个:

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

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

10-07 20:04