Bryhton projects for Android

The following represents the fundamental structure of a Brython project, illustrating its essential components and organization.

[ ]:
brython_app/
    .p4a                    # Configuration files for Python-for-Android
    blacklist.txt           # List of items to exclude from the build
    whitelist.txt           # List of items to include in the build
    brython_app/
-->     radiant/            # Radiant module, more details at: [Radiant Compiler GitHub](https://github.com/dunderlab/python-radiant_compiler/tree/main/radiant)
        main.py             # Main script for the Brython application

In the Brython app’s structure, special attention must be given to the radiant/ directory. It’s crucial to include the source code of these modules, as the python-for-android tool compiles source files into .pyo format. Pre-compiled modules or packages typically installed via package managers are not suitable for this process. This approach ensures that the python-for-android compiler effectively processes the source code of the Radiant Compiler, making them functional within the compiled Android application.

For additional configuration options and detailed instructions on building Android applications with Python, refer to the Python for Android Documentation.

[ ]:
# .p4a

--no-byte-compile-python
--private brython_app
--package org.example.brython_app
--name "My WebView Brython Application"
--dist_name brython_app
--version 0.1
--bootstrap webview
--requirements tornado,jinja2,markupsafe,pyjnius
--whitelist whitelist.txt
--port 5000

The path to a file containing blacklisted patterns that will be excluded from the final AAR.

[ ]:
# blacklist.txt

*.pyc

The path to a file containing whitelisted patterns that will be included in the AAR even if also blacklisted.

[ ]:
# whitelist.txt

sqlite3/*
lib-dynload/_sqlite3.so
*.py

For further guidance on developing the main.py file within your Brython project, consider consulting the Radiant Framework Documentation. This resource offers comprehensive information and examples to assist in leveraging the Radiant Framework effectively in your application.

[ ]:
# main.py

from radiant.framework.server import RadiantAPI, RadiantServer
from browser import html

class BareMinimum(RadiantAPI):

    def __init__(self, *args, **kwargs):
        """"""
        super().__init__(*args, **kwargs)
        self.body <= html.H1('Radiant Framework')

if __name__ == '__main__':
    RadiantServer('BareMinimum',
                  host='localhost',
                  port=5000,
                  )

To compile the project and generate the corresponding SDK file, follow the established build procedures outlined in the documentation. This process ensures that all necessary components are correctly assembled and the SDK file is prepared for deployment.

[ ]:
$ radiant_p4a apk --arch arm64-v8a