Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Plugins/Compilers/AndroidPluginCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ protected function buildMetaDataEntry(array $metaData): string
// Handle different value types
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
} elseif (is_string($value)) {
// Substitute ${ENV_VAR} placeholders, mirroring iOS info_plist handling
$value = $this->substituteEnvPlaceholders($value);
}

return "<meta-data android:name=\"{$name}\" android:value=\"{$value}\" />";
Expand Down Expand Up @@ -648,6 +651,9 @@ protected function buildComponentMetaData(array $metaDataEntries): string
} elseif ($value !== null) {
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
} elseif (is_string($value)) {
// Substitute ${ENV_VAR} placeholders, mirroring iOS info_plist handling
$value = $this->substituteEnvPlaceholders($value);
}
$xml .= " <meta-data android:name=\"{$name}\" android:value=\"{$value}\" />\n";
}
Expand Down
84 changes: 84 additions & 0 deletions tests/Feature/Plugins/AndroidCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,90 @@ public function it_adds_meta_data_with_value_inside_service(): void
$this->assertStringContainsString('</service>', $content);
}

/**
* @test
*
* Application-level meta-data values should have ${ENV_VAR} placeholders
* substituted from the environment, matching iOS info_plist handling.
*/
public function it_substitutes_env_placeholders_in_application_meta_data(): void
{
putenv('NATIVEPHP_TEST_META_KEY=resolved-secret');
$_ENV['NATIVEPHP_TEST_META_KEY'] = 'resolved-secret';

try {
$plugin = $this->createTestPlugin([
'android' => [
'permissions' => [],
'dependencies' => [],
'meta_data' => [
['name' => 'com.example.API_KEY', 'value' => '${NATIVEPHP_TEST_META_KEY}'],
],
],
]);

$this->mockRegistry
->shouldReceive('all')
->andReturn(collect([$plugin]));

$this->compiler->compile();

$manifestPath = $this->testBasePath.'/android/app/src/main/AndroidManifest.xml';
$content = $this->files->get($manifestPath);

$this->assertStringContainsString('<meta-data android:name="com.example.API_KEY" android:value="resolved-secret" />', $content);
$this->assertStringNotContainsString('${NATIVEPHP_TEST_META_KEY}', $content);
} finally {
putenv('NATIVEPHP_TEST_META_KEY');
unset($_ENV['NATIVEPHP_TEST_META_KEY']);
}
}

/**
* @test
*
* Component-level (service) meta-data values should also have ${ENV_VAR}
* placeholders substituted from the environment.
*/
public function it_substitutes_env_placeholders_in_service_meta_data(): void
{
putenv('NATIVEPHP_TEST_META_KEY=resolved-secret');
$_ENV['NATIVEPHP_TEST_META_KEY'] = 'resolved-secret';

try {
$plugin = $this->createTestPlugin([
'android' => [
'permissions' => [],
'dependencies' => [],
'services' => [
[
'name' => 'com.example.MyService',
'exported' => false,
'meta_data' => [
['name' => 'com.example.API_KEY', 'value' => '${NATIVEPHP_TEST_META_KEY}'],
],
],
],
],
]);

$this->mockRegistry
->shouldReceive('all')
->andReturn(collect([$plugin]));

$this->compiler->compile();

$manifestPath = $this->testBasePath.'/android/app/src/main/AndroidManifest.xml';
$content = $this->files->get($manifestPath);

$this->assertStringContainsString('<meta-data android:name="com.example.API_KEY" android:value="resolved-secret" />', $content);
$this->assertStringNotContainsString('${NATIVEPHP_TEST_META_KEY}', $content);
} finally {
putenv('NATIVEPHP_TEST_META_KEY');
unset($_ENV['NATIVEPHP_TEST_META_KEY']);
}
}

/**
* @test
*
Expand Down
Loading