expo-manifest-placeholders
v0.3.0
Published
An Expo config plugin to set manifest placeholders for Android gradle automatically
Downloads
35
Maintainers
Readme
expo-manifest-placeholders
English
An Expo config plugin that automatically injects manifestPlaceholders into your Android app/build.gradle during expo prebuild. Useful for SDKs that read placeholder values from AndroidManifest.xml (e.g. push notification, map, or analytics SDKs).
Installation
npm install expo-manifest-placeholders
# or
yarn add expo-manifest-placeholders
# or
bun add expo-manifest-placeholdersexpo must already be installed in your project (peer dependency).
Usage
Add the plugin to app.json or app.config.js and pass the plugin options as the second argument:
{
"expo": {
"plugins": [
[
"expo-manifest-placeholders",
{
"enabled": true,
"manifestPlaceholders": {
"JPUSH_APPKEY": "your-app-key",
"JPUSH_CHANNEL": "developer-default"
}
}
]
]
}
}Then run prebuild:
npx expo prebuild -p androidGenerated output
The plugin inserts a block inside defaultConfig in android/app/build.gradle:
defaultConfig {
// @generated begin expo-manifest-placeholders
manifestPlaceholders += [
JPUSH_APPKEY: "your-app-key",
JPUSH_CHANNEL: "developer-default"
]
// @generated end expo-manifest-placeholders
// ...
}These placeholders can then be referenced in AndroidManifest.xml:
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" />Options
| Key | Type | Default | Description |
| --- | --- | --- | --- |
| enabled | boolean | true | Whether the plugin is active. When false, existing generated blocks are removed and no new placeholders are added. |
| manifestPlaceholders | Record<string, string> | — | Placeholder key-value pairs written to manifestPlaceholders in build.gradle. |
To temporarily disable the plugin while keeping it in your config:
{
"enabled": false,
"manifestPlaceholders": {
"JPUSH_APPKEY": "your-app-key"
}
}Notes
- Android only — this plugin does not modify iOS configuration.
- Idempotent — re-running
expo prebuildreplaces the previous generated block instead of duplicating it. - Disable cleanup — setting
enabledtofalseremoves previously generated content without writing new placeholders. - Managed & bare workflow — works with any Expo project that uses config plugins and prebuild.
Development
git clone https://github.com/likeSo/expo-manifest-placeholders.git
cd expo-manifest-placeholders
bun install
bun run buildSee the example/ directory for a working sample app.
License
MIT © Aron
中文
一个 Expo Config Plugin,在运行 expo prebuild 时自动向 Android 的 app/build.gradle 注入 manifestPlaceholders。适用于需要从 AndroidManifest.xml 读取占位符值的 SDK(例如推送、地图、统计等)。
安装
npm install expo-manifest-placeholders
# 或
yarn add expo-manifest-placeholders
# 或
bun add expo-manifest-placeholders项目中需已安装 expo(peer dependency)。
用法
在 app.json 或 app.config.js 中注册插件,并将插件配置作为第二个参数传入:
{
"expo": {
"plugins": [
[
"expo-manifest-placeholders",
{
"enabled": true,
"manifestPlaceholders": {
"JPUSH_APPKEY": "你的AppKey",
"JPUSH_CHANNEL": "developer-default"
}
}
]
]
}
}然后执行 prebuild:
npx expo prebuild -p android生成结果
插件会在 android/app/build.gradle 的 defaultConfig 中插入如下代码块:
defaultConfig {
// @generated begin expo-manifest-placeholders
manifestPlaceholders += [
JPUSH_APPKEY: "你的AppKey",
JPUSH_CHANNEL: "developer-default"
]
// @generated end expo-manifest-placeholders
// ...
}之后即可在 AndroidManifest.xml 中引用这些占位符:
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" />配置说明
| 键 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| enabled | boolean | true | 是否启用插件。设为 false 时会删除已生成的配置,但不会写入新的占位符。 |
| manifestPlaceholders | Record<string, string> | — | 占位符键值对,会写入 build.gradle 中的 manifestPlaceholders。 |
临时禁用插件(同时清理已生成内容):
{
"enabled": false,
"manifestPlaceholders": {
"JPUSH_APPKEY": "你的AppKey"
}
}注意事项
- 仅支持 Android — 不会修改 iOS 配置。
- 可重复执行 — 多次运行
expo prebuild会替换已有生成块,不会产生重复内容。 - 禁用即清理 — 将
enabled设为false会移除之前生成的内容,且不会写入新的占位符。 - Managed & Bare 工作流 — 适用于使用 config plugin 和 prebuild 的 Expo 项目。
本地开发
git clone https://github.com/likeSo/expo-manifest-placeholders.git
cd expo-manifest-placeholders
bun install
bun run build可参考 example/ 目录中的示例项目。
许可证
MIT © Aron
