Cached and templated files in python-for-android builds

I’ve more than once seen people confused by how python-for-android constructs an Android project that can be compiled into an APK. Since p4a uses various cached and templated files, it’s easy to get confused trying to edit things only to find your changes are overwritten when you run p4a again.

Here’s a quick summary of what’s what.

Bootstraps

The core project files are all in the bootstraps directory. A bootstrap is basically an Android project, containing java sources, JNI stuff to be compiled, and project management files like the AndroidManifest.xml and build.gradle.

Note: Some of these files are built from templates, e.g. in the main SDL2 bootstrap you can find build.tmpl.gradle, AndroidManifest.tmpl.xml etc. in the templates subdirectory.

If you edit the code in these bootstrap directories, the changes will always take effect if you rebuild your whole project, but might not affect anything if you repeat a previous build. This is due to caching of previous build components. You can always guarantee that everything is cleared to be rebuilt using p4a clean dists builds (or there are other tricks if you look into it).

Build directories

Most of the individual python-for-android recipes are built in separate build directories. The location of these depends on the OS: on Linux the default is ~/.local/share/python-for-android, especially ~/.local/share/python-for-android/other_builds. When you build a recipe, it is copied here for the build to be run. These folders also cache builds, so if you e.g. build two different projects using python3 then the same build directory is used both times, reducing time spent compiling.

You can edit code in ~/.local/share/python-for-android/other_builds, but it isn’t recommended unless you have a good idea what python-for-android will overwrite or cache on each run. It is, however, sometimes useful during development.

Dists

Dists are p4a’s fully compiled Android projects, including the bundled output of all the different requirements specified by the user. On Linux, their default location is ~/.local/share/python-for-android/dists.

Every time you build an APK using p4a apk ..., this essentially runs gradle from an appropriate dist directory (i.e. the one with the recipes you wanted). At this point, nothing new is built or copied from the build directories, so changes you make to p4a’s recipes or build directories have no effect on the output. However, templated files such as AndroidManifest.tmpl.xml are rebuilt every time. That means that you must edit the templates themselves if you want your changes to make it to the APK.

You can always run p4a clean dists to delete the existing Android projects. Next time you run p4a apk ..., a new dist will be created.

Buildozer

When using buildozer, everything works basically the same except that the build and dist directories can be found in $PROJECT_DIR/.buildozer/android/platform/build instead of ~/.local/share/python-for-android. The python-for-android source code is stored in $PROJECT_DIR/.buildozer/android/platform/python-for-android.

Cached and templated files in python-for-android builds

I’ve more than once seen people confused by how python-for-android constructs an Android project that can be compiled into an APK. Since p4a uses various cached and templated files, it’s easy to get confused trying to edit things only to find your changes are overwritten when you run p4a again.

Here’s a quick summary of what’s what.

Bootstraps

The core project files are all in the bootstraps directory. A bootstrap is basically an Android project, containing java sources, JNI stuff to be compiled, and project management files like the AndroidManifest.xml and build.gradle.

Note: Some of these files are built from templates, e.g. in the main SDL2 bootstrap you can find build.tmpl.gradle, AndroidManifest.tmpl.xml etc. in the templates subdirectory.

If you edit the code in these bootstrap directories, the changes will always take effect if you rebuild your whole project, but might not affect anything if you repeat a previous build. This is due to caching of previous build components. You can always guarantee that everything is cleared to be rebuilt using p4a clean dists builds (or there are other tricks if you look into it).

Build directories

Most of the individual python-for-android recipes are built in separate build directories. The location of these depends on the OS: on Linux the default is ~/.local/share/python-for-android, especially ~/.local/share/python-for-android/other_builds. When you build a recipe, it is copied here for the build to be run. These folders also cache builds, so if you e.g. build two different projects using python3 then the same build directory is used both times, reducing time spent compiling.

You can edit code in ~/.local/share/python-for-android/other_builds, but it isn’t recommended unless you have a good idea what python-for-android will overwrite or cache on each run. It is, however, sometimes useful during development.

Dists

Dists are p4a’s fully compiled Android projects, including the bundled output of all the different requirements specified by the user. On Linux, their default location is ~/.local/share/python-for-android/dists.

Every time you build an APK using p4a apk ..., this essentially runs gradle from an appropriate dist directory (i.e. the one with the recipes you wanted). At this point, nothing new is built or copied from the build directories, so changes you make to p4a’s recipes or build directories have no effect on the output. However, templated files such as AndroidManifest.tmpl.xml are rebuilt every time. That means that you must edit the templates themselves if you want your changes to make it to the APK.

You can always run p4a clean dists to delete the existing Android projects. Next time you run p4a apk ..., a new dist will be created.

Buildozer

When using buildozer, everything works basically the same except that the build and dist directories can be found in $PROJECT_DIR/.buildozer/android/platform/build instead of ~/.local/share/python-for-android. The python-for-android source code is stored in $PROJECT_DIR/.buildozer/android/platform/python-for-android.

python-for-android 0.6 released

We’ve just officially released python-for-android 0.6. The new version can be downloaded via pip, or will be used by buildozer automatically in new installations. This release contains about 130 new commits from 14 different contributors. Thanks to everyone involved!

python-for-android is a packaging tool for turning Python scripts and apps into Android APKs. It was originally created for use with the Kivy graphical framework, but now supports multiple kinds of Python app including Kivy, PySDL2, a webview interface with Flask or other webserver backend, plain Python scripts without a GUI, or other possibilities such as Python builds for use in other applications.

As planned following the release of python-for-android 0.5, the new version includes some relatively major changes and improvements. In particular, python-for-android should now work with all recent versions of the Android SDK and NDK. On the SDK side this means python-for-android now uses gradle if available, although this doesn’t require any changes to the configuration on the user side.

For the next release I intend to focus work on checking and updating python-for-android’s build recipes to make sure they are all properly compatible with one another and with different build configurations. I’d also like to improve our automated testing, in order to more easily detect and fix issues as they appear.

For full instructions and further information, see the python-for-android documentation.

python-for-android 0.6 released

We’ve just officially released python-for-android 0.6. The new version can be downloaded via pip, or will be used by buildozer automatically in new installations. This release contains about 130 new commits from 14 different contributors. Thanks to everyone involved!

python-for-android is a packaging tool for turning Python scripts and apps into Android APKs. It was originally created for use with the Kivy graphical framework, but now supports multiple kinds of Python app including Kivy, PySDL2, a webview interface with Flask or other webserver backend, plain Python scripts without a GUI, or other possibilities such as Python builds for use in other applications.

As planned following the release of python-for-android 0.5, the new version includes some relatively major changes and improvements. In particular, python-for-android should now work with all recent versions of the Android SDK and NDK. On the SDK side this means python-for-android now uses gradle if available, although this doesn’t require any changes to the configuration on the user side.

For full instructions and further information, see the python-for-android documentation.

python-for-android 0.5 released

We’ve just officially released python-for-android 0.5. The new version can be downloaded via pip, or will be used by buildozer automatically in new installations. This release contains about 300 commits from almost 40 different contributors. Thanks to everyone involved!

python-for-android is a packaging tool for turning Python scripts and apps into Android APKs. It was originally created for use with the Kivy graphical framework, but now supports multiple kinds of Python app including Kivy, PySDL2, a webview interface with Flask or other webserver backend, plain Python scripts without a GUI, or other possibilities such as Python builds for use in other applications.

This release contains many fixes and improvements to all parts of the toolchain. Now that these have been released as stable, we intend to move quickly to make some larger improvements including supporting gradle builds, and better support for Python 3 in some recipes.

For full instructions and further information, see the python-for-android documentation.

python-for-android 0.5 released

We’ve just officially released python-for-android 0.5. The new version can be downloaded via pip, or will be used by buildozer automatically in new installations. This release contains about 300 commits from almost 40 different contributors. Thanks to everyone involved!

python-for-android is a packaging tool for turning Python scripts and apps into Android APKs. It was originally created for use with the Kivy graphical framework, but now supports multiple kinds of Python app including Kivy, PySDL2, a webview interface with Flask or other webserver backend, plain Python scripts without a GUI, or other possibilities such as Python builds for use in other applications.

This release contains many fixes and improvements to all parts of the toolchain. Now that these have been released as stable, we intend to move quickly to make some larger improvements including supporting gradle builds, and better support for Python 3 in some recipes.

For full instructions and further information, see the python-for-android documentation.

Pyonic interpreter 1.3 released: Adds support for loading and executing files

I’ve just released Pyonic interpreter 1.3. As usual you can download it from Google Play, for Python 2.7 or Python 3.6. The APKs can also be downloaded directly from Github (where the source code is also available).

The new filebrowser interface in Pyonic interpreter.

The main addition in this release is a file browser interface, which gives Pyonic the ability to load and execute files in the interpreter. This is mildly useful on its own, and I’ve had comments that people would like to be able to do it, but it’s also groundwork for full support for file editing support. I hope to add these features in a future version.

Pyonic interpreter 1.3 released: Adds support for loading and executing files

I’ve just released Pyonic interpreter 1.3. As usual you can download it from Google Play, for Python 2.7 or Python 3.6. The APKs can also be downloaded directly from Github (where the source code is also available).

The new filebrowser interface in Pyonic interpreter.

The main addition in this release is a file browser interface, which gives Pyonic the ability to load and execute files in the interpreter. This is mildly useful on its own, and I’ve had comments that people would like to be able to do it, but it’s also groundwork for full support for file editing support. I hope to add these features in a future version.

Pyonic interpreter 1.2 released: Now supports Python 3.6 and input functions

I’ve just released Pyonic interpreter 1.2. As usual, you can get it from Google Play, now for Python 2.7 or Python 3.6. The APKs can also de bownloaded directly from Github (where the source code is also available).

Pyonic interpreter showing docstring and autocompletion options

This is the first release to target Python 3.6 on Android (not just Python 3.5), which is made possible by recent additions to python-for-android. I expect to do a separate python-for-android release to announce this shortly.

The main change to the app this release is support for the input and (in Python 2) raw_input functions. These would previously crash as the interpreter isn’t really being run in a shell, so the way they try to take input doesn’t work. They are now overridden with new replacements, which should hopefully behave roughly the same way as the originals are supposed to, but via a more convenient popup gui for the text to be entered.

I’m still working on file editing and other Python management functions, but there didn’t seem to be any reason to delay a release since according to the Google Play reviews people are trying and failing to use the input functions.

Pyonic interpreter 1.2 released: Now supports Python 3.6 and input functions

I’ve just released Pyonic interpreter 1.2. As usual, you can get it from Google Play, now for Python 2.7 or Python 3.6. The APKs can also be downloaded directly from Github (where the source code is also available).

Pyonic interpreter showing docstring and autocompletion options

This is the first release to target Python 3.6 on Android (not just Python 3.5), which is made possible by recent additions to python-for-android. I expect to do a separate python-for-android release to announce this shortly.

The main change to the app this release is support for the input and (in Python 2) raw_input functions. These would previously crash as the interpreter isn’t really being run in a shell, so the way they try to take input doesn’t work. They are now overridden with new replacements, which should hopefully behave roughly the same way as the originals are supposed to, but via a more convenient popup gui for the text to be entered.

I’m still working on file editing and other Python management functions, but there didn’t seem to be any reason to delay a release since according to the Google Play reviews people are trying and failing to use the input functions.