dpa99c / cordova-custom-config

Cordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
318 stars 84 forks source link

custom tag gets added to xml/config.xml #150

Closed gunhaxxor closed 5 years ago

gunhaxxor commented 5 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior:

I'm installing this plugin using the command ionic cordova plugin add cordova-custom-config I'm adding the following to config.xml inside the <platform name="android"> tag:

<custom-config-file target="AndroidManifest.xml" parent="/*">
  <uses-permission android:name="android.permission.CAMERA" />
</custom-config-file>

The plugin adds the permission tag to AndroidManifest.xml as expected. But, it also adds the following to the file platforms\android\app\src\main\res\xml\config.xml:

<custom-config-file target="AndroidManifest.xml" parent="/*">
  <uses-permission android:name="android.permission.CAMERA" />
</custom-config-file>

This results in the following build error when running ionic cordova run android --device:

...
C:\dev\social-robot\social-robot-ionic\platforms\android\app\src\main\res\xml\config.xml:76: AAPT: error: unbound prefix.

C:\dev\social-robot\social-robot-ionic\platforms\android\app\src\main\res\xml\config.xml:76: error: unbound prefix.

:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
21 actionable tasks: 1 executed, 20 up-to-date
(node:20972) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
C:\dev\social-robot\social-robot-ionic\platforms\android\app\src\main\res\xml\config.xml:76: AAPT: error: unbound prefix.

C:\dev\social-robot\social-robot-ionic\platforms\android\app\src\main\res\xml\config.xml:76: error: unbound prefix.
...

Expected behavior:

I expect that the custom-config-file tag doesn't get added to the config.xml in platforms\android\app\src\main\res\xml\

Environment information

Android build issue:

iOS build issue:

dpa99c commented 5 years ago

Since you are using the android XML namespace, did you declare it in the config.xml for the XML parser to reference?

For example, see the example project's config.xml

FYI cordova-android deploys the project config.xml to platforms\android\app\src\main\res\xml\config.xml in order to make the configuration available to the native Android layer.

gunhaxxor commented 5 years ago

Thanks for the swift answer. It seems like that indeed was the problem.