From a44675cc21944e885912bded92976fd88142d20f Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 9 Sep 2026 18:49:29 -0700 Subject: [PATCH] Add --extra-manifest-application-xml for injecting elements inside There's currently no way to add an arbitrary child element (like a , needed for e.g. a FileProvider) inside in the generated AndroidManifest.xml: - --extra-manifest-xml writes at the root, as a sibling of -- a there is invalid, providers must be nested inside . - --extra-manifest-application-arguments only splices into the opening tag's attribute list, so it can't hold a full child element either. This is a real gap: a FileProvider (needed to hand another app, e.g. a camera app, a content:// Uri instead of a file:// one and avoid FileUriExposedException on API 24+) requires exactly this kind of entry, and there's currently no supported way to add one without patching the rendered manifest after the fact via a p4a.hook. Adds --extra-manifest-application-xml, rendered immediately before in every bootstrap's manifest template, alongside the two existing options. --- .../_sdl_common/build/templates/AndroidManifest.tmpl.xml | 1 + pythonforandroid/bootstraps/common/build/build.py | 9 +++++++++ .../qt/build/templates/AndroidManifest.tmpl.xml | 1 + .../build/templates/AndroidManifest.tmpl.xml | 1 + .../build/templates/AndroidManifest.tmpl.xml | 1 + .../webview/build/templates/AndroidManifest.tmpl.xml | 1 + 6 files changed, 14 insertions(+) diff --git a/pythonforandroid/bootstraps/_sdl_common/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/_sdl_common/build/templates/AndroidManifest.tmpl.xml index 4aba5fc40c..66ec71d05e 100644 --- a/pythonforandroid/bootstraps/_sdl_common/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/_sdl_common/build/templates/AndroidManifest.tmpl.xml @@ -142,6 +142,7 @@ {% for a in args.add_activity %} {% endfor %} + {{ args.extra_manifest_application_xml }} diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 2eb2d555fc..04f56ac391 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -1050,6 +1050,15 @@ def create_argument_parser(): ap.add_argument('--extra-manifest-application-arguments', default='', help='Extra arguments to be added to the tag of' 'AndroidManifest.xml') + ap.add_argument('--extra-manifest-application-xml', default='', + help=('Extra xml to write directly inside the ' + 'element of AndroidManifest.xml, i.e. as a sibling of /' + '/etc, as opposed to --extra-manifest-application-arguments ' + 'which only supports attributes on the tag itself. ' + 'Needed for e.g. a entry (such as a FileProvider), which ' + 'neither --extra-manifest-xml (a sibling of , at the ' + ' root) nor --extra-manifest-application-arguments ' + '(attributes only) can express.')) ap.add_argument('--manifest-placeholders', dest='manifest_placeholders', default='[:]', help=('Inject build variables into the manifest ' 'via the manifestPlaceholders property')) diff --git a/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml index 1385bdbd03..4b110b89e8 100644 --- a/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml @@ -105,6 +105,7 @@ {% for a in args.add_activity %} {% endfor %} + {{ args.extra_manifest_application_xml }} diff --git a/pythonforandroid/bootstraps/service_library/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/service_library/build/templates/AndroidManifest.tmpl.xml index 2add7e7bf2..51f0d8a001 100644 --- a/pythonforandroid/bootstraps/service_library/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/service_library/build/templates/AndroidManifest.tmpl.xml @@ -15,6 +15,7 @@ android:process=":service_{{ name }}" android:exported="true" /> {% endfor %} + {{ args.extra_manifest_application_xml }} diff --git a/pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml index 651a70aea6..fda2bcd36d 100644 --- a/pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml @@ -94,6 +94,7 @@ {% endif %} + {{ args.extra_manifest_application_xml }} diff --git a/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml index 3a99e87470..b87c5d51a7 100644 --- a/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml @@ -102,6 +102,7 @@ {% endif %} + {{ args.extra_manifest_application_xml }}