繁体   English   中英

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

[英]Gradle "manifest requires a placeholder substitution" error but manifestPlaceholders supplies a value

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

这是 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 即

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]

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

对于那些由于库清单中定义的 manifestPlaceholders 而遇到清单合并/清单注入问题的人,问题来自您需要在库manifestPlaceholders manifestPlaceholders一个值。 当您在消费应用程序中注入您的真实价值时,该价值不会被覆盖。 为了解决这个问题,您应该只为库中的debug版本定义这些manifestPlaceholders值。

像这样:

android.buildTypes.debug.manifestPlaceholders = [
    authScheme: 'clientAppReplaces', authHost: 'clientAppReplaces'
]

通过这样做,您将能够构建您的库。 同时还让客户端应用程序为manifestPlaceholders提供正确的值。 让你的图书馆做它应该做的所有繁重的工作。 这是可能的,因为库构建为发布构建(除非另有定义)。

客户端应用build.gradle示例:

defaultConfig {
    applicationId "com.app.manifestPlaceholders"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode project.ext.versionCode
    versionName project.ext.versionName

    manifestPlaceholders = [authScheme: 'customSchemeValue', authHost: 'hostValue']
}

这个

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

应该是这样的

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

您需要将 applicationId 占位符添加到应用程序 gradle。 在更新到 Gradle 2.2.0-alpha1 后,集成 Firebase 会发生这种情况

android {
    ...
    defaultConfig {
        applicationId "com.example.my.app"
        ...
    }
}

请参阅: 无法获取提供程序 com.google.firebase.provider.FirebaseInitProvider

我在我的值周围留下了 ${} 符号:

<meta-data android:name="net.example" android:value="${XXXX}" />

请注意+=操作应用于manifestPlaceholders而不是= 这是有意的,也是必需的,因为较新版本的Flutter SDK在底层进行了一些更改以处理 multidex。 使用=而不是+=可能会导致如下错误:

Attribute application@name at AndroidManifest.xml:5:9-42 requires a placeholder substitution but no value for <applicationName> is provided.

如果您看到此错误,请更新您的build.gradle以改用+=

如果您的应用程序使用 Google 地图

在运行应用程序之前,您需要一个 Google Maps API 密钥。

         To get one, follow the directions here:

            https://developers.google.com/maps/documentation/android-sdk/get-api-key

         Once you have your API key (it starts with "AIza"), define a new property in your
         project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
         "YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
    -->
  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM