Short instructions to compile the multilanguage Python/C/Java Mnemosyne client
for Android, using Ubuntu:

- precompile and package the Python code (libmnemosyne, ...) by typing
  'make android' in the main development directory.
  Make sure to have an install of Python 3.10 to do this compilation.
- Install NDK 21.3, API level 30 for compatibility with the python-for-android libraries.

These libraries are in the github repository, but if you want to install them yourself, do the following:

- Look at the instructions here, on a Ubuntu machine:
   https://python-for-android.readthedocs.io/en/latest/quickstart/#installation
- However, they are a bit outdated, so use the following modifications:

- Download command line tools from https://developer.android.com/studio#Requirements
- sudo apt-get install openjdk-11-jdk if needed
- "Error: Could not determine SDK root. Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: <sdk>/cmdline-tools/latest/" : Rename the unpacked directory from cmdline-tools to tools, and place it under e.g. android/cmdline-tools
make sure the tools directory is inside a directory called cmdline-tools (https://stackoverflow.com/questions/65262340/cmdline-tools-could-not-determine-sdk-root) 
- use double quotes for arguments of sdkmanager. From the cmdline-tools directory: 
tools/bin/sdkmanager --install "platforms;android-33"
tools/bin/sdkmanager --install "ndk;25.1.8937393"
tools/bin/sdkmanager --list | grep build : find latest build tools
tools/bin/sdkmanager --install "build-tools;33.0.2"

(If you get "Warning: Failed to read or create install properties file." run it as root).

- .bashrc:

export ANDROIDSDK="$HOME/android/cmdline-tools" # The directory where tools is located, not the SDK dir
export ANDROIDNDK="$HOME/android/ndk/25.1.8937393"
export ANDROIDAPI="33"  # Target API version of your application
export NDKAPI="26"  # Minimum supported API version of your application
# export ANDROIDNDKVER="r19c" # Deprecated

p4a create --arch=x86_64 --dist-name=x86_64 --blacklist-requirements=android,libffi,openssl --requirements=python3 --force-build

p4a create --arch=arm64-v8a --dist-name=arm64-v8a --blacklist-requirements=android,libffi,openssl --requirements=python3 --force-build

p4a create --arch=x86 --dist-name=x86 --blacklist-requirements=android,libffi,openssl --requirements=python3 --force-build

p4a create --arch=armeabi-v7a --dist-name=armeabi-v7a  --blacklist-requirements=android,libffi,openssl --requirements=python3 --force-build

- If you need to reset: 'p4a clean_all'
  
- copy header files from 
~\.local\share\python-for-android\build\other_builds\python3\<arch>__ndk_target_26\python3\Include
to android/dependencies/python/include/<arch>

- copy libraries libpython3.9.so and libsqlite3 from 
~\.local\share\python-for-android\dists\<arch>\libs\<arch>
to android/dependencies/python/lib/<arch>

- modules are in ~\.local\share\python-for-android\dists\<arch>\_python_bundle__<arch> \_python_bundle\modules
- from modules, delete _decimal, _pickle, _testcapi, audioop, cmath (saves 500 kb)
- copy the result to android/app/src/<arch with _ instead of - >/assets/python/modules for the extension modules
  (these have to go in the assets, since they cannot start with lib_... , as otherwise android refuses
  to package them in a release build)

- stdlib.zip is in 
~\.local\share\python-for-android\dists\<arch>\_python_bundle\_python_bundle
- pruning some libraries to reduce the space somewhat: from stdlib.zip,
  delete _pydecimal.pyc, pydoc.pyc, turtle.pyc, pickletools.pyc, pickle.pyc,
  unittest, turtledemo, pydoc_data, distutils (saves 500 kb)
- copy to android\app\src\main\assets\python (this can be shared by all architectures, so only do this once.)

- update git

On the Android Studio side:
- Update Android Studio
- Also install the NKD in Android Studio, using Tools - SDK Manager - SDK tools
- Delete old emulator images from <home>/.android/avd
- in File - Project structure, upgrade Gradle version, Android Gradle Plugin Version.
- build.gradle for Module: set nkdversion
- delete mnemosyne-proj\mnemosyne\mnemosyne\android\app\.cxx and\build
- edit mnemosyne-proj\mnemosyne\mnemosyne\android\app\src\main\cpp\CMakeLists.txt to update the Python version
- rebuild project

Note: if you get unexpected results, remove app/build, app/<archs>, clean project and rebuild project.

During development, set the build variant (Build - Select Build variant) to
whatever architecture you use for developping (physical device, emulator, ...).
Use the debug version for deploying on an emulator, so that there's no
issues with signing

Then, for release, do 'Build - Generate Signed Bundle / APK'
