Skip to content

Inject manifest placeholders into test components#107

Open
ojh102 wants to merge 1 commit into
google:mainfrom
ojh102:fix/test-component-manifest-placeholders
Open

Inject manifest placeholders into test components#107
ojh102 wants to merge 1 commit into
google:mainfrom
ojh102:fix/test-component-manifest-placeholders

Conversation

@ojh102

@ojh102 ojh102 commented Jun 26, 2026

Copy link
Copy Markdown

Fixes #41.

Problem

The plugin injects manifest placeholders only into the main variant. Both unit-test and android-test manifests are merged from the same sources and reference the same placeholders (e.g. ${MAPS_API_KEY}), but they never receive a value.

This was harmless until AGP started validating the test manifest merge. On recent AGP versions processDebugUnitTestManifest (and the equivalent android-test task) fails the build:

Attribute meta-data#com.google.android.geo.API_KEY@value at AndroidManifest.xml
requires a placeholder substitution but no value for <MAPS_API_KEY> is provided.
Validation failed, exiting

The main/release build works fine — only test variants break. This is the same <MAPS_API_KEY> not provided failure reported in #41 (the Try to repro #41 branch confirms it reproduces).

Isolation

Triggered purely by the AGP version, everything else held constant:

AGP processDebugUnitTestManifest
9.0.1 ✅ passes
9.1.1 ❌ fails (<MAPS_API_KEY> not provided)

Fix

After injecting the main variant, also inject manifest placeholders into its nested test components:

  • Add TestComponent.inject applying only manifest placeholders (test components don't generate a BuildConfig, so unlike Variant.inject it skips buildConfigFields). Since both UnitTest and AndroidTest are the variant's nested TestComponents, iterating nestedComponents covers both.
  • In SecretsPlugin, inject the nested test components alongside the main variant for every property source (defaults, properties, build-type, flavor).
  • Bump the compiled-against AGP 7.0.4 → 7.4.0 — the first version where TestComponent.manifestPlaceholders exists — kept as low as possible to preserve compatibility for consumers still on AGP 7.x. (The sample app and tests keep building against 8.4.2 to exercise the fix on newer AGP.)

Test

Added test component receives manifest placeholders, verifying injection and ignore-list handling. The plugin compiles against AGP 7.4.0; the sample app and tests run against 8.4.2. All existing tests pass.

@ojh102 ojh102 force-pushed the fix/test-component-manifest-placeholders branch from 8c866af to 0160eba Compare June 26, 2026 03:28
The plugin injects manifest placeholders only into the main variant. Test
manifests (unit test and android test) are merged from the same sources and
reference the same placeholders (e.g. ${MAPS_API_KEY}), but never receive a
value. With recent AGP versions that validate the test manifest merge, the
build fails with:

  Attribute meta-data#...@value requires a placeholder substitution but no
  value for <MAPS_API_KEY> is provided.

Fixes the long-standing report in google#41.

Changes:
- Add `TestComponent.inject` that applies only manifest placeholders (test
  components do not generate a BuildConfig). This covers both UnitTest and
  AndroidTest, which are the variant's nested TestComponents.
- After injecting the main variant, also inject its nested test components.
- Bump the compiled-against AGP from 7.0.4 to 7.4.0 — the first version where
  `TestComponent.manifestPlaceholders` exists — kept as low as possible to
  preserve compatibility for consumers still on AGP 7.x.
- Add a unit test covering test-component placeholder injection.
@ojh102 ojh102 force-pushed the fix/test-component-manifest-placeholders branch from 0160eba to fbe4bca Compare June 26, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merged Manifest error

1 participant