Build System | termux/termux-api | DeepWiki

https://deepwiki.com/termux/termux-api/4.1-build-system

Get free private DeepWikis in Devin

DeepWiki

termux/termux-api

Menu

Build System

Relevant source files

The Termux API project uses Gradle as its build system to compile, test, and package the Android application. This document describes the Gradle configuration, project structure, dependencies, and customization options used in the Termux API. For information about extending the API with new functionality, see Extending Termux API.

Gradle Configuration Overview

The build system uses a multi-file Gradle configuration that defines how the Termux API application is built, versioned, and packaged.

Gradle Build System FilesProject-wide
configurationsProject
propertiesProject
propertiesGradle
versionExecutesbuild.gradleapp/build.gradlegradle.propertiesgradle/wrapper/
gradle-wrapper.propertiesgradlew/gradlew.bat
Scripts

Sources: build.gradle app/build.gradle gradle.properties gradle/wrapper/gradle-wrapper.properties gradlew gradlew.bat

Application Configuration

The app’s core configuration is defined in the application’s build.gradle file, which specifies the build parameters, SDK versions, application metadata, and dependencies.

Package and Version Configuration

SDK ConfigurationApplication IdentificationOverrideProvidesProvidesProvidesApp NamingTERMUX_PACKAGE_NAME
com.termuxTERMUX_APP_NAME
TermuxTERMUX_API_APP_NAME
Termux:APInamespace
com.termux.apiapplicationId
com.termux.apiversionCode
1000versionName
0.51.0compileSdk
35minSdk
24targetSdk
28Environment Variablesgradle.properties

Sources: app/build.gradle3-23 gradle.properties23-25

The build system supports dynamic version naming via environment variables, allowing CI/CD systems to specify version information:

  • TERMUX_API_APP__BUILD__APP_VERSION_NAME: Overrides the application version name
  • TERMUX_API_APP__BUILD__APK_VERSION_TAG: Customizes the APK filename

Sources: app/build.gradle7-8 app/build.gradle54-58

Build Types

The application defines two build types with specific configurations: Build TypeMinifyShrink ResourcesProGuardSigningreleaseYesNoYes-debugNoNoNotestkey_untrusted.jks

Sources: app/build.gradle25-43

Dependency Management

The Termux API relies on several dependencies to provide its functionality:

DependenciesAndroid LibrariesTermux LibrariesUtility LibrariesGoogle Material
1.12.0AndroidX Biometric
1.2.0-alpha05AndroidX Media
1.7.0AndroidX Preference
1.2.1Termux Shared Library
com.termux.termux-app:termux-shared:9ee1c9d5adDesugar JDK Libraries
1.1.5ListenableFuture
(Conflict Resolution)

Sources: app/build.gradle68-82

Java Compatibility

The project uses Java 11 features while ensuring backward compatibility through the Desugar JDK libraries:compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 }

Sources: app/build.gradle46-52 app/build.gradle69

APK Output Configuration

The build system customizes the output APK filenames to include version information:applicationVariants.all { variant -> variant.outputs.all { output -> outputFileName = new File("termux-api-app_" + (apkVersionTag ? apkVersionTag : "v" + versionName + "+" + variant.buildType.name) + ".apk") } }

Examples of generated filenames:

  • termux-api-app_v0.51.0+release.apk
  • termux-api-app_v0.51.0+debug.apk
  • termux-api-app_custom-tag.apk (when TERMUX_API_APP__BUILD__APK_VERSION_TAG is set)

Sources: app/build.gradle54-59

Gradle Wrapper

The project uses Gradle Wrapper to ensure consistent builds across different development environments and CI/CD systems:

ExecutesUsesDownloads
specific versionExecutesDeveloperGradle Wrapper
gradlew/gradlew.batgradle-wrapper.propertiesGradle 8.9Build Scripts

Key wrapper configuration:

  • Gradle version: 8.9
  • Distribution type: all (includes sources, docs)
  • Distribution URL: https://services.gradle.org/distributions/gradle-8.9-all.zip

Sources: gradle/wrapper/gradle-wrapper.properties gradlew gradlew.bat

Repository Configuration

The project accesses dependencies from multiple repositories:allprojects { repositories { google() mavenCentral() //mavenLocal() maven { url "https://jitpack.io" } } }

This configuration allows the project to:

  • Access official Android libraries from Google’s repository
  • Access general open-source libraries from Maven Central
  • Access GitHub-hosted libraries through JitPack
  • Optionally use locally published libraries (commented out by default)

Sources: build.gradle11-18

Custom Tasks and Version Validation

The build system includes custom tasks and validation logic:

versionName Task

A custom task that outputs the version name:task versionName { doLast { print android.defaultConfig.versionName } }

Sources: app/build.gradle85-89

Version Name Validation

The build enforces semantic versioning through regex validation:static def validateVersionName(String versionName) { // Semantic version regex if (!java.util.regex.Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\$", versionName)) throw new GradleException("The versionName '" + versionName + "' is not a valid version as per semantic version '2.0.0' spec...") }

Sources: app/build.gradle91-97

Build Process Flow

The complete build process involves several steps from initialization to APK generation:

ReleaseDebugBuild InitiatedGradle Wrapper LaunchesInitialize ProjectRead Properties FilesResolve Environment VariablesValidate Version NameResolve DependenciesCompile Java/Kotlin CodeProcess ResourcesBuild Type?Minify CodeSign with Debug KeyPackage APKName APK FileOutput APK

Sources: app/build.gradle build.gradle gradle.properties

Environment Setup

To use the build system effectively, developers need:

  1. JDK 11 or newer
  2. Android SDK with build tools and platform tools
  3. Environment variables for custom builds:
    • TERMUX_API_APP__BUILD__APP_VERSION_NAME
    • TERMUX_API_APP__BUILD__APK_VERSION_TAG

Sources: app/build.gradle7-8 app/build.gradle50-51

Common Build Commands

CommandDescription./gradlew assembleBuild all variants./gradlew assembleDebugBuild debug APK./gradlew assembleReleaseBuild release APK./gradlew versionNameDisplay version name./gradlew cleanClean build outputs./gradlew installDebugInstall debug APK

Sources: app/build.gradle85-89 build.gradle20-22 gradlew

Packaging Optimization

The build system excludes unnecessary native libraries from the final APK:packagingOptions { // Remove terminal-emulator and termux-shared JNI libs added via termux-shared dependency exclude "lib/*/libtermux.so" exclude "lib/*/liblocal-socket.so" }

This optimization ensures the APK doesn’t include native libraries that are already part of the main Termux application.

Sources: app/build.gradle61-65

Ask Devin about termux/termux-apiDeep Research

Leave a comment

Design a site like this with WordPress.com
Get started