Project

General

Profile

Actions

Wiki » History » Revision 2

« Previous | Revision 2/3 (diff) | Next »
Liam H, 09/24/2024 09:52 AM


WIP Report: FOSS Android SDK Build

Current Status:

We have successfully created a pkgbuild/APKBUILD for the android-sdk based on the Rebuild-SDK, which builds without errors. However, upon further investigation, we discovered that the Android repository includes over 187 binary dependencies, such as Go and Rust, in the prebuilt repository. Patching these dependencies manually is a tedious task.

New Approach:

We have found an unofficial CMake-based build system for Android command line utilities, which is already used in many Linux distributions. Our next step is to evaluate the possibility of creating a merge request to build the Android SDK using CMake.

Call for Help:

We are seeking assistance in writing the necessary CMake files to support this new build system. Specifically, we are looking for help with:

  • Creating CMake files for the Android SDK build process
  • Integrating the CMake build system with the existing Android repository

APKBUILD for alpine linux

pkgname=android-sdk
pkgver=14.0.0
_pkgrev=r74
pkgrel=0
pkgdesc="android sdk without google binaries" 
url="https://git.replicant.us/contrib/wizzard/Android/SDK-Rebuild" 
arch="all" 
license="APACHE" 
makedepends=" 
bison
flex
git
gnupg
gperf
libx11-static
libxml2
libxslt
mesa-dev
ncurses-static
python3
repo
rsync
unzip
openssh
bash
" 
source="" 
builddir="$srcdir/" 
options="!check net" 

prepare() {
    git config --global user.email "you@example.com" r
    git config --global user.name "Your Name" 
    sdkver="${pkgver}_${_pkgrev}" 
    echo $sdkver
    # TODO maybe make init fast using this: https://android.googlesource.com/platform/sdk/+/refs/tags/android-14.0.0_r74/README.txt
    repo init -u https://android.googlesource.com/platform/manifest -b android-$sdkver --depth=1 </dev/null
    sed -i '/prebuilt/d' "$builddir"/.repo/manifests/default.xml
    while ! repo sync --current-branch -j"$(nproc)"; do
        echo "repo sync failed, retrying..." 
    done
}

build() {
    export TARGET_RELEASE=trunk
    BUILD_VARIANT='eng'
    export BUILD_NUMBER=${BUILD_VARIANT}."${sdkver}" 
    # needed, because otherwise conscrypt build will fail. ART and some other
    # dependencies need to be built from source.
    export ART_MODULE_BUILD_FROM_SOURCE=true
    export MODULE_BUILD_FROM_SOURCE=true
    echo "$BUILD_NUMBER" 

    cd src
    . build/envsetup.sh

    lunch sdk-$TARGET_RELEASE-$BUILD_VARIANT
    make -j"$(nproc)" sdk dist sdk_repo
}

package() {
    install -Dm755 "$srcdir"/build/dist/android-sdk_linux-x86-"$BUILD_VARIANT".zip "$pkgdir"/opt/android-sdk
}

The build script has been tested on trisquel using this script

#!/bin/env bash

# Source the PKGBUILD file
. APKBUILD

# Set environment variables
if [ -z "$pkgver" ] || [ -z "$_pkgrev" ]; then
    echo "Error: pkgver and/or _pkgrev not set in PKGBUILD" 
    exit 1
fi

# Check if required Ubuntu packages are available, install them if not
sudo apt-get update
for pkg in bison flex git gnupg gperf libx11-dev libxml2 libxslt1-dev libgl1-mesa-dev libncurses5-dev python3 repo rsync unzip openssh-client; do
    if ! dpkg -s $pkg &>/dev/null; then
        echo "Installing $pkg..." 
        sudo apt-get install -y $pkg
    fi
done

# Run the prepare, build, and package functions
prepare
build
package

# Save the SHA256 of the zip
sha256sum=$(sha256sum "$pkgdir"/opt/android-sdk/android-sdk_linux-x86-"$BUILD_VARIANT".zip | cut -d' ' -f1)
echo "SHA256 of android-sdk: $sha256sum" 
echo "$sha256sum" >android-sdk.sha256

Tooling:

We either write the cmake files by hand or to utilize Bear, a tool that generates a compilation database for clang tooling, to aid in the creation of the CMake files. Bear can generate a JSON compilation database during the build process when make is called, which will help us to port the build process to cmake, as the JSON complilation database will contain all the files, that where required for building the sdk

Next Steps:

  • Evaluate the feasibility of building the Android SDK with CMake
  • Create a merge request to integrate the CMake build system into the Android repository
  • Collaborate with the community to write the necessary CMake files

Help Wanted:

If you have experience with CMake and Android build systems, we would appreciate your help in writing the CMake files and integrating the new build system. Your contributions will be invaluable in helping us create a FOSS version of the Android SDK.

[[https://github.com/nmeum/android-tools]]
[[https://github.com/rizsotto/Bear]]

Updated by Liam H 21 days ago · 2 revisions

Also available in: PDF HTML TXT