Search code examples
matchcode-documentationblacklistp4apython-for-android

What is the usage of blacklist.txt in pythonforandroid (p4a)?


In the documentation of pythonforandroid, at https://python-for-android.readthedocs.io/en/latest/buildoptions/, there is a build option described called blacklist.

  • --blacklist: The path to a file containing blacklisted patterns that will be excluded from the final APK. Defaults to ./blacklist.txt

However, not a word can be found anywhere about how to use this file and what exactly the patterns are supposed to represent. For instance, is this used to exclude libraries, files, or directories? Do the patterns match file names or contents? What is the syntax of the patterns, or an example of a valid blacklist.txt file?


Solution

  • This file should contain a list of glob patterns, i.e. as implemented by fnmatch, one per line. These patterns are compared against the full filepath of each file in your source dir, probably using a global filepath but I'm not certain about that (it might be relative to the source dir).

    For instance, the file could contain the following lines:

    *.txt
    */test.jpg
    

    This would prevent all files ending with .txt from being included in the apk, and all files named test.jpg in any subfolder.

    If using buildozer, the android.blacklist_src buildozer.spec option can be used to point to your choice of blacklist file.