p4a: exclude files from being placed in the apk

147 views
Skip to first unread message

Abstract Donut

unread,
Nov 9, 2020, 11:33:26 PM11/9/20
to Kivy users support
I have many files within my project which won't show up in the final apk. To optimize for space, I need to exclude these files. In the documentation for p4a, at https://python-for-android.readthedocs.io/en/latest/buildoptions/, I see that there is a build option called blacklist.

  • --blacklist: The path to a file containing blacklisted patterns that will be excluded from the final APK. Defaults to ./blacklist.txt
Does this do what I want? If so, is there any documentation for what the contents of blacklist.txt should be? To try and see how it works, I created a file blacklist.txt in the project directory which excluded a single image resource from my project as a test, but the image resource still made it into the apk after running p4a apk. 

Thanks in advance

Robert Flatt

unread,
Nov 10, 2020, 12:14:49 AM11/10/20
to Kivy users support
Its all undocumented magic to me.

buildozer option names are mostly the same, as they are just passed to p4a.
Look at the default buildozer.spec for potential enlightenment you could try: exclude_dirs , exclude_exts

Degenerate Tech

unread,
Nov 10, 2020, 12:44:29 AM11/10/20
to Kivy users support
how to backlist python module in buildozer.spec file ?say for sqlite3 ..i want to reduce the size of apk

Abstract Donut

unread,
Nov 10, 2020, 1:08:42 PM11/10/20
to Kivy users support
No cigar, unfortunately.

usage: p4a [-h] [--private PRIVATE] --package PACKAGE --name NAME
           [--numeric-version NUMERIC_VERSION] --version VERSION [--launcher]
           [--permission PERMISSIONS [PERMISSIONS ...]]
           [--meta-data META_DATA] [--uses-library ANDROID_USED_LIBS]
           [--asset /path/to/source:dest] [--icon ICON] [--service SERVICES]
           [--presplash PRESPLASH] [--presplash-color PRESPLASH_COLOR]
           [--window] [--orientation ORIENTATION]
           [--android-entrypoint ANDROID_ENTRYPOINT]
           [--android-apptheme ANDROID_APPTHEME]
           [--add-compile-option COMPILE_OPTIONS]
           [--add-gradle-repository GRADLE_REPOSITORIES]
           [--add-packaging-option PACKAGING_OPTIONS] [--wakelock]
           [--blacklist BLACKLIST] [--whitelist WHITELIST] [--release]
           [--with-debug-symbols] [--add-jar ADD_JAR] [--add-aar ADD_AAR]
           [--depend DEPENDS] [--sdk SDK_VERSION] [--minsdk MIN_SDK_VERSION]
           [--allow-minsdk-ndkapi-mismatch] [--intent-filters INTENT_FILTERS]
           [--with-billing BILLING_PUBKEY] [--add-source EXTRA_SOURCE_DIRS]
           [--try-system-python-compile] [--no-compile-pyo] [--sign]
           [--add-activity ADD_ACTIVITY]
           [--activity-launch-mode ACTIVITY_LAUNCH_MODE]
           [--allow-backup ALLOW_BACKUP] [--no-optimize-python]
           [--extra-manifest-xml EXTRA_MANIFEST_XML]
p4a: error: unrecognized arguments: --exclude_dirs=images/logo

Abstract Donut

unread,
Nov 10, 2020, 1:25:16 PM11/10/20
to Kivy users support

Abstract Donut

unread,
Nov 11, 2020, 2:20:01 PM11/11/20
to Kivy users support
I'm suprised this question is getting so few responses. Excluding files seems like a very simple problem, and a very important one to get right. Is there simply no way to do this with p4a?


On Monday, November 9, 2020 at 8:33:26 PM UTC-8, Abstract Donut wrote:

Robert Flatt

unread,
Nov 11, 2020, 2:48:15 PM11/11/20
to Kivy users support
Rearrange the project so that the unwanted files are somewhere else 😉 or try buildozer 😲

Abstract Donut

unread,
Nov 11, 2020, 3:53:00 PM11/11/20
to Kivy users support
Looks like that's what I have to do. My current strategy is to have a shell script that moves unwanted files to the parent directory before running p4a, then moves them back afterword. It just doesn't seem like a clean method.

Oh well. Thanks for the help :)

Alexander Taylor

unread,
Nov 11, 2020, 6:15:45 PM11/11/20
to Kivy users support
> Is there simply no way to do this with p4a?

No, the blacklist file you've already discovered is the way to do this. I've posted some brief details of how to use it on stackoverflow. It hasn't ever been developed much because nobody has ever found the time to improve it, contributions welcome.
Reply all
Reply to author
Forward
0 new messages