問題描述
我正在嘗試在 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模板網!