kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.28k stars 1.83k forks source link

String argument from Buildozer not decoded. #2905

Open RobertFlatt opened 10 months ago

RobertFlatt commented 10 months ago

Checklist

Versions

Description

In buildozer.spec , setting:

android.extra_manifest_application_arguments = somefile.xml

Where somefile.xml contains:

android:usesCleartextTraffic="true"

results in an excaped string argument from Buildozer to p4a:

# Run ['/usr/bin/python3', '-m', 'pythonforandroid.toolchain', 'apk', '--bootstrap', 'sdl2', '--dist_name', 'oauth_gspread_example', '--name', 'OG', '--version', '0.1', '--package', 'org.reallyatest.oauth_gspread_example', '--minsdk', '21', '--ndk-api', '21', '--private', '/home/bobf/ex/oauth_gspread_example/.buildozer/android/app', '--permission', 'INTERNET', '--android-entrypoint', 'org.kivy.android.PythonActivity', '--android-apptheme', '@android:style/Theme.NoTitleBar', '--orientation', 'portrait', '--window', '--enable-androidx', '--copy-libs', '--add-source', '/home/bobf/ex/oauth_gspread_example/java', '--extra-manifest-application-arguments="android:usesCleartextTraffic=\\"true\\" "', '--arch', 'arm64-v8a', '--color=always', '--storage-dir=/home/bobf/ex/oauth_gspread_example/.buildozer/android/platform/build-arm64-v8a', '--ndk-api=21', '--ignore-setup-py', '--debug']

the key part to note is the value from somefile.xml has been quoted and escaped:

'--extra-manifest-application-arguments="android:usesCleartextTraffic=\\"true\\" "'

The value is written without interpretation to AndroidManifest.xml as an escaped string

 <application android:label="@string/app_name"
                 android:debuggable="true"
                 android:icon="@mipmap/icon"
                 android:allowBackup="true"

                 "android:usesCleartextTraffic=\"true\" "
                 android:theme="@android:style/Theme.NoTitleBar"   

Gradle dies with:

AndroidManifest.xml; lineNumber: 53; columnNumber: 18; Element type "application" must be followed by either attribute specifications, ">" or "/>".

The last but one line in the AndroidManifest.xml snippet above should the same a the contents of somefile.xml

                 android:usesCleartextTraffic="true" 

Presumably, Buildozer has to quote and escape in order to pass the argument, so the issue is assumed to be a failure of the p4a parser to decode the argument.

Since we presumably know Buildozer's (quote and escape) encoding algorithm, it should be possible to successfully decode. A simpler approach might be a new p4a argument receiving the file name, and Buildozer supplying the file name.

I didn't test but this may also apply to the buildozer.spec android.extra_manifest_xml option.

Snagovskiy-Denis commented 5 months ago

I want to bump this issue. It's a small, but it's annoying and easy to fix.

snuq commented 4 months ago

I ran into this exact same issue trying to get this manifest permission put into my app as well... did you figure out any workaround for it?

Snagovskiy-Denis commented 4 months ago

did you figure out any workaround for it?

I edited the AndroidManifest.tmpl.xml file in the local/project .buildozer directory and directly put my additional manifest arguments in it.

snuq commented 4 months ago

did you figure out any workaround for it?

I edited the AndroidManifest.tmpl.xml file in the local/project .buildozer directory and directly put my additional manifest arguments in it.

i managed to figure out how to do this as well, not exactly easy to find this file tho! for anyone who might be coming her from a google search like i did, i found this manifest template at:

.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/dists/<app name>/templates/AndroidManifest.tmpl.xml

Snagovskiy-Denis commented 4 months ago

did you figure out any workaround for it?

I edited the AndroidManifest.tmpl.xml file in the local/project .buildozer directory and directly put my additional manifest arguments in it.

i managed to figure out how to do this as well, not exactly easy to find this file tho! for anyone who might be coming her from a google search like i did, i found this manifest template at:

.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/dists/<app name>/templates/AndroidManifest.tmpl.xml

You could just run the find -name AndroidManifest.tmpl.xml command and edit the one that applies to your app. Nevertheless, I'm glad this helped you.