Project

General

Profile

Wiki » History » Version 1

Liam H, 09/24/2024 09:51 AM
update

1 1 Liam H
**WIP Report: FOSS Android SDK Build**
2
3
**Current Status:**
4
5
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.
6
7
**New Approach:**
8
9
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.
10
11
**Call for Help:**
12
13
We are seeking assistance in writing the necessary CMake files to support this new build system. Specifically, we are looking for help with:
14
15
* Creating CMake files for the Android SDK build process
16
* Integrating the CMake build system with the existing Android repository
17
18
h3. APKBUILD for alpine linux
19
<pre><code class="shell">
20
pkgname=android-sdk
21
pkgver=14.0.0
22
_pkgrev=r74
23
pkgrel=0
24
pkgdesc="android sdk without google binaries"
25
url="https://git.replicant.us/contrib/wizzard/Android/SDK-Rebuild"
26
arch="all"
27
license="APACHE"
28
makedepends="
29
bison
30
flex
31
git
32
gnupg
33
gperf
34
libx11-static
35
libxml2
36
libxslt
37
mesa-dev
38
ncurses-static
39
python3
40
repo
41
rsync
42
unzip
43
openssh
44
bash
45
"
46
source=""
47
builddir="$srcdir/"
48
options="!check net"
49
50
prepare() {
51
	git config --global user.email "you@example.com" r
52
	git config --global user.name "Your Name"
53
	sdkver="${pkgver}_${_pkgrev}"
54
	echo $sdkver
55
	# TODO maybe make init fast using this: https://android.googlesource.com/platform/sdk/+/refs/tags/android-14.0.0_r74/README.txt
56
	repo init -u https://android.googlesource.com/platform/manifest -b android-$sdkver --depth=1 </dev/null
57
	sed -i '/prebuilt/d' "$builddir"/.repo/manifests/default.xml
58
	while ! repo sync --current-branch -j"$(nproc)"; do
59
		echo "repo sync failed, retrying..."
60
	done
61
}
62
63
build() {
64
	export TARGET_RELEASE=trunk
65
	BUILD_VARIANT='eng'
66
	export BUILD_NUMBER=${BUILD_VARIANT}."${sdkver}"
67
	# needed, because otherwise conscrypt build will fail. ART and some other
68
	# dependencies need to be built from source.
69
	export ART_MODULE_BUILD_FROM_SOURCE=true
70
	export MODULE_BUILD_FROM_SOURCE=true
71
	echo "$BUILD_NUMBER"
72
73
	cd src
74
	. build/envsetup.sh
75
76
	lunch sdk-$TARGET_RELEASE-$BUILD_VARIANT
77
	make -j"$(nproc)" sdk dist sdk_repo
78
}
79
80
package() {
81
	install -Dm755 "$srcdir"/build/dist/android-sdk_linux-x86-"$BUILD_VARIANT".zip "$pkgdir"/opt/android-sdk
82
}
83
</code></pre>
84
85
The build script has been tested on trisquel using this script
86
<pre><code class="shell">
87
#!/bin/env bash
88
89
# Source the PKGBUILD file
90
. APKBUILD
91
92
# Set environment variables
93
if [ -z "$pkgver" ] || [ -z "$_pkgrev" ]; then
94
	echo "Error: pkgver and/or _pkgrev not set in PKGBUILD"
95
	exit 1
96
fi
97
98
# Check if required Ubuntu packages are available, install them if not
99
sudo apt-get update
100
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
101
	if ! dpkg -s $pkg &>/dev/null; then
102
		echo "Installing $pkg..."
103
		sudo apt-get install -y $pkg
104
	fi
105
done
106
107
# Run the prepare, build, and package functions
108
prepare
109
build
110
package
111
112
# Save the SHA256 of the zip
113
sha256sum=$(sha256sum "$pkgdir"/opt/android-sdk/android-sdk_linux-x86-"$BUILD_VARIANT".zip | cut -d' ' -f1)
114
echo "SHA256 of android-sdk: $sha256sum"
115
echo "$sha256sum" >android-sdk.sha256
116
117
</code></pre>
118
119
120
121
**Tooling:**
122
123
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
124
125
**Next Steps:**
126
127
* Evaluate the feasibility of building the Android SDK with CMake
128
* Create a merge request to integrate the CMake build system into the Android repository
129
* Collaborate with the community to write the necessary CMake files
130
131
**Help Wanted:**
132
133
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.
134
135
[[https://github.com/nmeum/android-tools]]
136
[[https://github.com/rizsotto/Bear]]