The first article of the series: Make Android Great (Again) - Dive into Termux
This article assumes that you have learned the following:
This article also supposes you've got the following equipment:
Before starting to explain how to compile Termux package compilation, it is necessary to share some of the best practices that can significantly improve efficiency.
Best practices can greatly improve efficiency, make the mood more pleasant, greatly reduce the time from getting started to giving up and reduce the probability.
Run the following commands on mobile phone's Termux APP:
pkg install openssh passwd # set current user's password sshd # start openssh-server
Run the following commands on the computer, or use other ssh connection software to fill in the corresponding parameters to connect:
ssh -p 8022 xxx@[your phone IP]
Compile directly with Docker.
This way you will have fewer weird operating system exclusive problems. Regardless of whether the host machine is Windows, Mac or Linux itself, it is recommended to use docker to run the official Ubuntu image provided by Termux packages to compile.
In this way, the compilation environment can be started with one click, without installing too many toolchain program on your Ubuntu system, and there will be no environmental configuration problems.
Clone the latest Termux packages repository:
git clone https://github.com/termux/termux-packages.git cd termux-packages
Run the docker script inside the Termux packages to create a compilation environment:
After entering the docker environment, you can freely run various compilation commands.
Custom parameters before entering Docker:
# Customize container name, e.g.: export CONTAINER_NAME=hhj_termux_armv8 # Customize the mirror address, e.g.: export TERMUX_BUILDER_IMAGE_NAME=ghcr.io/termux/package-builder # Finally, run the docker environment and automatically apply the above parameters bash scripts/run-docker.sh
How to access host machine's 127.0.0.1 inside docker?
--network host \ in the appropriate position below
$SUDO docker run \
How to mount more local directories?
--volume [host directory]:[docker directory] \ below
--volume $VOLUME \
After entering docker, you can set the following environment variables and set them as needed.
# Network proxy settings export https_proxy=http://127.0.0.1:7071 export http_proxy=http://127.0.0.1:7071 export no_proxy="localhost,127.0.0.1,dl.google.com" # Set compilation parameters, adjust as needed export TERMUX_PKG_API_LEVEL=24 export TERMUX_PKG_MAINTAINER=HHJ export TERMUX_ARCH=aarch64 # arm, aarch64, i686 or x86_64. export TERMUX_TOPDIR=/home/builder/termux-packages/termux-build # compile output directory # Path setting, enhance compatibility export ANDROID_HOME=/home/builder/lib/android-sdk-9123335 export NDK=/home/builder/lib/android-ndk-r25c export PATH=/home/builder/termux-packages/termux-build/_cache/cmake-3.24.2/bin:$PATH
Usually suitable for debugging, when you need to manually run compilation commands in docker, without using scripts.
The following environment variables can be used to configure the environment for
make and other commands.
For more detailed information, please refer to: https://developer.android.com/ndk/guides/other_build_systems?hl=zh-cn
Note: Do not use host build or host build
Note 2: If you still don't understand what this section is talking about, just skip this section.
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64 export TARGET=aarch64-linux-android export API=24 export AR=$TOOLCHAIN/bin/llvm-ar export CC=$TOOLCHAIN/bin/$TARGET$API-clang export AS=$CC export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ export LD=$TOOLCHAIN/bin/ld export RANLIB=$TOOLCHAIN/bin/llvm-ranlib export STRIP=$TOOLCHAIN/bin/llvm-strip export SETUPTOOLS_USE_DISTUTILS=local
First make sure that you have configured and entered docker according to the previous section.
Take compiling Python as an example. By default, the dependencies are compiled first, and then the ontology is compiled:
If you want to download dependencies from the official apt repo, only compile python itself locally:
./build-package.sh -I python
For example, inside Termux's official apt repo, python has reached python 3.11, and the official apt repo only keeps the latest version, meaning the old version of Python can no longer be installed through
apt install or
If we want to use Python3.10 again, what should we do? We can compile her by ourselves. The following are the detailed steps.
cd [git repository directory of your termux-packages] git checkout bootstrap-2022.10.23-r1+apt-android-7 # The latest version that supports python 3.10
Confirm the Python version number in
_MAJOR_VERSION=3.10, which proves that the switching was successful.
# Clear the flags of compiled packages rm -rf /data/data/.built-packages # Clear all compiled caches rm -rf $TERMUX_TOPDIR && mkdir $TERMUX_TOPDIR
Note: It is not recommended to use the
-I parameter, because many apt software inside the official apt repo have been updated, and old versions of Python dependencies may have compatibility issues. It is better to recompile them all through source code.
After the compilation is successful, copy all the files in the
output directory to the phone
Then execute the following command on your mobile phone's Termux APP, to install them manually (note that the dependencies should be installed first and then the main ones):
dpkg -i xxx.deb
After compiling, we might find that dpkg installation is too troublesome to deal with various dependencies, so how to create an apt service that can be hosted by yourself?
Suppose you already have a web service.
Inside docker or Linux host machine, use the following command to build apt related files and directories:
pip3 install termux-apt-repo # https://github.com/termux/termux-apt-repo # Generate the apt directory files in the directory named "backup" cd xxx/termux-packages termux-apt-repo --use-hard-links output backup stable main # Synchronize to the directory of the web service (if you use ftp or other methods, please work around it yourself) rsync --delete -rvP backup/dists xxx/www/html/termux-packages # Assume that this directory corresponds to https://hhj.name/termux-packages
Then execute the following command on the Termux of the mobile phone
echo "deb [trusted=yes] https://hhj.name/termux-packages/ stable main" > $PREFIX/etc/apt/sources.list cat <<EOF > $PREFIX /etc/termux/chosen_mirrors WEIGHT=999 https://hhj.name/termux-packages/ EOF apt update pkg search python # Confirm that python is the version compiled by yourself pkg install python # Happy to install the python compiled by myself