Issue
I have just seen that support for AAB files have just been introduced in Python for Android (p4a). Considering that, fom August 2021, new apps are required to publish with the Android App Bundle on Google Play, this is a crucial addition for any Python dev working on Android apps.
Since I'm currently using Buildozer via Docker, I'd like to know which are the steps to make it generating an .aab instead of (or along to) the traditional .apk
For the sake of clarity, here is what I use to run Buildozer from inside a container (using Docker for Windows) to make the .apk file:
docker run --interactive --tty --rm --volume "<full_path_to_project_dir>":/home/user/hostcwd kivy/buildozer -v android debug
I've seen that there is a temporary workaround, but it involves using Android Studio, that I don't use and would like to avoid using. Moreover, it refers to virtual machine users, but I'm not sure if this applies to Docker users too.
Solution
The community has finally completed the AAB support for Buildozer. Although it is still a pending pull request, it is already possible to create the AAB, and I have figured out how to do it using Docker.
I have found two very interesting gists that helped me a lot (this one about creating an AAB with Buildozer on Ubuntu, and another one about signing an AAB on the same platform). However, I have run everything on Windows via Docker, so I think it is a good idea to share how I did it.
Clone the feat/aab-support branch of the Buildozer repository in your local machine:
git clone --single-branch --branch feat/aab-support https://github.com/misl6/buildozer.git
Move into the root folder of the project you have just cloned, and build the container:
cd buildozer docker build -t buildozer-aab .
Before using Buildozer to actually build the AAB, we need to generate a new buildozer.spec file, since there are new fields that need to be included for build AAB. To do that, move into the root folder of your app project, remove or rename any old buildozer.spec file, and run the following command:
docker run --interactive --tty --rm --volume "<full_path_to_app_project_dir>":/home/user/hostcwd kivy/buildozer -v init
Change the following fields in the newly generated buildozer.spec:
android.archs = arm64-v8a, armeabi-v7a android.release_artifact = aab p4a.branch = develop
Now we need to create a keystore to sign our AAB. To this end, run the following commands on a WSL shell (I used WSL 2 with Ubuntu on Windows 10):
mkdir -p /path/to/keystores/ keytool -genkey -v -keystore /path/to/keystores/<keystore>.keystore -alias <keystore-alias> -keyalg RSA -keysize 2048 -validity 10000 keytool -importkeystore -srckeystore /path/to/keystores/<your-new-key>.keystore -destkeystore /path/to/keystores/<keystore>.keystore -deststoretype pkcs12
The second line will generate a keystore with a validity of 10000 days (which is higher than the minimum of 25 years required by Google). You need to replace
<keystore>
with the filename you want to use for your keystore, and set an<keystore-alias>
(typically the name of your application). You will be asked to add a password. Try to avoid special characters.Now move your keystores folder (the one in
/path/to/keystores/
) to a folder that is reachable from outside WSL (e.g. you can move it in your desktop). In the following, I will assume that your keystores folder is now inC:\Users\test\Desktop\keystores
We are now finally ready to build the AAB. First, be sure to remove any .buildozer folder within your app root folder. Then run the following:
docker run --interactive --tty --rm \ --volume "<app-project-folder>":/home/user/hostcwd \ --volume "<app-project-folder>\.buildozer":/home/user/.buildozer \ --volume "C:\Users\test\Desktop\keystores":/home/user/keystores \ -e P4A_RELEASE_KEYSTORE=/home/user/keystores/<keystore>.keystore \ -e P4A_RELEASE_KEYSTORE_PASSWD="<your-password>" \ -e P4A_RELEASE_KEYALIAS_PASSWD="<your-password>" \ -e P4A_RELEASE_KEYALIAS="<keystore-alias>" \ buildozer-aab -v android release
Answered By - Vito Gentile