Skip to content

2. Build environment

Prakhar Shukla edited this page Jan 21, 2020 · 1 revision

Structure

Files and directories available inside build environment:

  • ./debs - directory where built packages will be placed. Does not exist by default.

  • ./disabled-packages - directory with packages excluded from main build tree due to various reasons.

  • ./ndk-patches - directory with patches for Android NDK sysroot.

  • ./packages - directory where all packages (scripts and patches) are located.

  • ./sample - sample structure for creating new package.

  • ./scripts - internal parts of build system and some utility scripts.

  • ./build-all.sh - script for building all available packages.

  • ./build-package.sh - script for building one or more packages.

  • ./clean.sh - script for cleaning build environment.

Setting up

Docker container

Using official Docker image is a recommended way for building Termux packages which ensures that you have same environment as Termux maintainers and therefore builds are reproducible.

If you have Docker installed and running, then launching build environment should be as simple as running

./scripts/run-docker.sh

Wait until latest image will be downloaded and then container's shell prompt should appear. The termux-packages folder will be mounted as /home/builder/termux-packages.

You may execute commands inside container without launching interactive shell by supplying them as arguments to ./scripts/run-docker.sh. Example:

./scripts/run-docker.sh ./build-package.sh libandroid-support

Sometimes Docker image should be updated. Following command will update image and delete outdated container:

./scripts/update-docker.sh

Building own Docker image

Dockerfile is located in ./scripts/ directory and configured to build Ubuntu-based image.

To build the Docker image, execute following commands:

cd ./scripts
docker build -t andronixapp/package-builder .

If you are getting error like -bash: /tmp/setup-ubuntu.sh: Permission denied, make sure that all *.sh files have permission 755 and umask is 0022.

Docker on Windows

For Windows users there is a PowerShell script available:

.\scripts\run-docker.ps1

Tips

  1. Multiple containers.

    You can have multiple containers running in parallel. Just set different container name as environment variable:

    CONTAINER_NAME=termux_builder_2 ./scripts/run-docker.sh
    
  2. Using unofficial Docker image.

    You can use a custom Docker image as environment variable TERMUX_BUILDER_IMAGE_NAME, but it also recommended to set a custom name for the container (like above):

    export TERMUX_BUILDER_IMAGE_NAME=username/termux-custom-builder
    export CONTAINER_NAME=custom-builder1
    ./scripts/run-docker.sh
    

VirtualBox VM

There is a Vagrantfile for setting up a VirtualBox Ubuntu installation.

  • Run vagrant plugin install vagrant-disksize to install disk size plugin for Vagrant.

  • Run cd scripts && vagrant up to setup and launch the virtual machine.

  • Run vagrant ssh to ssh into the virtual machine.

Host OS

We have scripts that automate installation of packages used in build process. For now only Ubuntu and Arch Linux distributions are supported. Note that all scripts execute commands under sudo.

For Ubuntu:

./scripts/setup-ubuntu.sh

For Arch Linux:

./scripts/setup-archlinux.sh

Additionally you will need to install Android SDK and NDK. By default, it is expected that both SDK and NDK are installed into $HOME/lib, so it is recommended to use following script to properly setup them:

./scripts/setup-android-sdk.sh
  1. List item

Important note

After properly setting up the building environment make sure that you these following things are properly setup.

  • The $TERMUX_ANDROID_HOME should be set to /data/data/studio.com.techriz.andronix/files/home
  • The $TERMUX_PREFIXshould be set to /data/data/studio.com.techriz.andronix/files/usr

These environmental variable can be set with executing this script with source env_build.sh

This script can also be used to import to set the variables essential for uploading the packages on Bintray (this action is restricted to only maintainers for the official repository). More info here.