This repository contains the build-wheel tool, which produces Android .whl files for Chaquopy.
build-wheel can build .whl files for all Android ABIs (armeabi-v7a, arm64-v8a, x86 and x86_64). However, the tool itself only runs on Linux x86-64. If you don't already have a Linux machine available, a cheap virtual server from somewhere like DigitalOcean will do just fine.
Create a recipe directory in packages. Its name must be in PyPI normalized form (PEP 503).
Alternatively, you can create this directory somewhere else, and pass its path when calling
build-wheel.py.
Inside the recipe directory, add the following files:
- A
meta.yamlfile. This supports a subset of Conda syntax, defined inmeta-schema.yaml. - For non-Python packages, a
build.shscript. Seebuild-wheel.pyfor environment variables which are passed to it. - If necessary, a
patchessubdirectory containing patch files.
The following examples are included:
- multidict: a minimal example, downloaded from PyPI.
- cython-example: a minimal example, built from a local directory.
- cryptography: a package with a build-time requirement.
- python-example: a pybind11-based package, downloaded from a Git repository.
- cmake-example: similar to python-example, but uses cmake. A patch is used to help cmake find the Android toolchain file.
- chaquopy-libzmq: a non-Python library, downloaded from a URL.
- pyzmq: a Python package which depends on a non-Python library. A patch is used to help
setup.pyfind the library. - scikit-learn: lists several build-time requirements in
meta.yaml:- The "build" requirement (Cython) will be installed automatically.
- The "host" requirements (NumPy etc.) should be downloaded from the public
repository and copied into
server/pypi/distbefore running the build. A patch is used to allow NumPy and SciPy to be imported during the build.
Docker is the easiest way to set up all of build-wheel's dependencies.
If necessary, install Docker using the instructions on its website.
Build the Docker images:
docker build -t chaquopy-base -f base.dockerfile .
docker build -t chaquopy-target target
docker build -t build-wheel server/pypi
If the server/pypi directory changes, you'll need to rerun the last of these commands to
update the build-wheel image.
Then run build-wheel from the server/pypi directory as follows:
docker run -v $(pwd)/dist:/root/pypi/dist build-wheel --toolchain target/toolchains/<abi> <package>
Where:
<abi>is an Android ABI.<package>is the name of the recipe directory created above.
The resulting .whl files will be generated in server/pypi/dist.
This is more convenient for development, but you'll have to set up all of build-wheel's dependencies manually. Use the Dockerfiles as a guide.
Then run build-wheel from the server/pypi directory as follows:
./build-wheel.py --toolchain ../../target/toolchains/<abi> <package>
<abi> and <package> are described above. The toolchains directory can be copied out of
the chaquopy-target image.
The resulting .whl files will be generated in server/pypi/dist.
.whl files can be built into your app using the pip
block in your
build.gradle file. First, add an options line to pass
--extra-index-url
with the location of the dist directory mentioned above. Either an HTTP URL or a local path
can be used. Then add an install line giving the name of your package.