Skip to content

Build Script Overview

Andy Crampton edited this page Sep 9, 2025 · 1 revision

Build Script Overview

The build_cpp.sh script is the heart of the library. Its purpose is to cross-compile GDAL and all of its C/C++ dependencies for each of the Android architectures required by the app.

General Workflow

  1. Architecture Loops: The script contains a main loop that iterates four times, once for each target Android architecture: armeabi-v7a, arm64-v8a, x86, and x86_64.

  2. build_for_target Function: Inside the loop, a master function named build_for_target is called. This function does the following for the given architecture:

    • Sets up environment variables (CC, CXX, CFLAGS, LDFLAGS, etc.) to point to the correct compiler and toolchain from the Android NDK.
    • Defines an "install" directory (e.g., build/arm64-v8a) where all the compiled libraries and headers for that specific architecture will be placed.
  3. Building Dependencies: The function then proceeds to build each dependency in sequence (e.g., PROJ, GEOS, SQLite, libpng). For each dependency, it runs its configure or cmake script with a --prefix flag pointing to the architecture-specific "install" directory. This ensures the compiled output is placed in the correct location.

  4. Building GDAL: Once all dependencies are built and "installed" into the build/ subdirectory, the script configures and builds GDAL itself. The GDAL configure script is pointed to the same "install" directory, allowing it to find the headers and libraries of all its dependencies.

  5. Final Output: The process results in a complete set of .so (shared object) files for each architecture. These are the final product of the script and are then copied into the Android project's gdal/src/main/jniLibs directory, where they are bundled by Gradle into the final APK.

Clone this wiki locally