Skip to content

Commit d067de3

Browse files
committed
fix: extract busybox from rootfs and hard-fail on missing assets
1 parent 15a6cec commit d067de3

2 files changed

Lines changed: 26 additions & 32 deletions

File tree

Android/app/build.gradle.kts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -186,45 +186,30 @@ tasks.register("prepareAssets") {
186186

187187
// Copy vap.sh
188188
val vapSh = File(toolsSrc, "vap.sh")
189-
if (vapSh.exists()) {
190-
vapSh.copyTo(File(assetTools, "vap.sh"), overwrite = true)
191-
println("prepareAssets: copied vap.sh")
192-
} else {
193-
println("prepareAssets: vap.sh not found at ${vapSh.absolutePath}, skipping.")
194-
}
189+
require(vapSh.exists()) { "prepareAssets: vap.sh not found at ${vapSh.absolutePath}" }
190+
vapSh.copyTo(File(assetTools, "vap.sh"), overwrite = true)
191+
println("prepareAssets: copied vap.sh")
195192

196193
// Copy start-ap
197194
val startAp = File(toolsSrc, "start-ap")
198-
if (startAp.exists()) {
199-
startAp.copyTo(File(assetTools, "start-ap"), overwrite = true)
200-
println("prepareAssets: copied start-ap")
201-
} else {
202-
println("prepareAssets: start-ap not found at ${startAp.absolutePath}, skipping.")
203-
}
195+
require(startAp.exists()) { "prepareAssets: start-ap not found at ${startAp.absolutePath}" }
196+
startAp.copyTo(File(assetTools, "start-ap"), overwrite = true)
197+
println("prepareAssets: copied start-ap")
204198

205-
// Copy busybox
199+
// Copy busybox (extracted from rootfs by build_rootfs.sh)
206200
val busybox = File(toolsSrc, "bin/busybox")
207-
if (busybox.exists()) {
208-
busybox.copyTo(File(assetBin, "busybox"), overwrite = true)
209-
println("prepareAssets: copied busybox")
210-
} else {
211-
println("prepareAssets: busybox not found at ${busybox.absolutePath}, skipping.")
212-
}
201+
require(busybox.exists()) { "prepareAssets: busybox not found at ${busybox.absolutePath}. Run rootfs-builder/build_rootfs.sh first." }
202+
busybox.copyTo(File(assetBin, "busybox"), overwrite = true)
203+
println("prepareAssets: copied busybox")
213204

214205
// Copy latest rootfs tarball
215-
if (outDir.exists()) {
216-
val tarballs = outDir.listFiles()?.filter { it.name.endsWith(".tar.xz") }
217-
?.sortedByDescending { it.lastModified() }
218-
val latest = tarballs?.firstOrNull()
219-
if (latest != null) {
220-
latest.copyTo(File(assetRootfs, latest.name), overwrite = true)
221-
println("prepareAssets: copied rootfs tarball ${latest.name}")
222-
} else {
223-
println("prepareAssets: no .tar.xz tarball found in ${outDir.absolutePath}, skipping.")
224-
}
225-
} else {
226-
println("prepareAssets: out/ directory not found at ${outDir.absolutePath}, skipping.")
227-
}
206+
require(outDir.exists()) { "prepareAssets: out/ directory not found at ${outDir.absolutePath}. Run rootfs-builder/build_rootfs.sh first." }
207+
val tarballs = outDir.listFiles()?.filter { it.name.endsWith(".tar.xz") }
208+
?.sortedByDescending { it.lastModified() }
209+
val latest = tarballs?.firstOrNull()
210+
require(latest != null) { "prepareAssets: no .tar.xz tarball found in ${outDir.absolutePath}. Run rootfs-builder/build_rootfs.sh first." }
211+
latest.copyTo(File(assetRootfs, latest.name), overwrite = true)
212+
println("prepareAssets: copied rootfs tarball ${latest.name}")
228213
}
229214
}
230215

rootfs-builder/build_rootfs.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ docker buildx build \
5656
-f "$DOCKERFILE" \
5757
"$(dirname "$0")"
5858

59+
# Extract the statically-linked busybox from the rootfs for host-side use
60+
# (Android lacks unshare/nsenter; the chroot engine needs this binary)
61+
BUSYBOX_DST="$(dirname "$0")/../backend/bin"
62+
mkdir -p "$BUSYBOX_DST"
63+
echo "Extracting busybox.static from rootfs tarball..."
64+
tar -xf "$TEMP_TAR" -O bin/busybox.static > "$BUSYBOX_DST/busybox"
65+
chmod +x "$BUSYBOX_DST/busybox"
66+
echo "Extracted busybox to $BUSYBOX_DST/busybox ($(du -h "$BUSYBOX_DST/busybox" | cut -f1))"
67+
5968
echo "Compressing (xz -9, multi-threaded)..."
6069
xz -T0 -9 -f "$TEMP_TAR"
6170
mv "${TEMP_TAR}.xz" "$FINAL_NAME"

0 commit comments

Comments
 (0)