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

- 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.8 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
- make sure the tools directory is inside a directory called cmdline-tools ( https://stackoverflow.com/questions/60440509/android-command-line-tools-sdkmanager-always-shows-warning-could-not-create-se )
- use single quotes for arguments of sdkmanager. From the cmdline-tools directory: 
tools/bin/sdkmanager --install "platforms;android-29"
tools/bin/sdkmanager --install "ndk;21.3.6528147"
tools/bin/sdkmanager --install "build-tools;30.0.2"

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

- .bashrc:

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

- p4a create --arch=armeabi-v7a,arm64-v8a,x86,x86_64 --blacklist-requirements=android,libffi,openssl
 (Note: creating all archs at the same time does not seem to work, so only
  create one arch at the time, and do 'p4a clean_all' in between)
  
- copy header files from 
~\.local\share\python-for-android\build\other_builds\python3\<arch>__ndk_target_21\python3\Include
to android/dependencies/python/include/<arch>

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

- modules are in ~\.local\share\python-for-android\dists\unnamed_dist_1__armeabi-v7a\_python_bundle\_python_bundle 
- 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\unnamed_dist_1__armeabi-v7a\_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.)

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, ...).

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

Note: python 3.9 seems under review for python-for-android https://github.com/kivy/python-for-android/pull/2337

