Auto-commit after successful build: update app gameplay/UI, improve build setup

Changed files:\nCrossCompileGitForAndroid.sh
app/build.gradle.kts
app/src/main/java/com/kawomi/githugandroid/GitRuntime.kt
app/src/main/jniLibs/arm64-v8a/libgit.so
This commit is contained in:
Joe Tretter
2026-04-22 20:01:03 -05:00
parent d5f05dacb0
commit 97db212a04
4 changed files with 31 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ NDK_DIR="$SDK_DIR/ndk/27.2.12479018"
TOOLBIN="$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin" TOOLBIN="$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin"
TMP_DIR="$PROJECT_DIR/.tmp-android-build" TMP_DIR="$PROJECT_DIR/.tmp-android-build"
GIT_SRC_DIR="$TMP_DIR/git-src" GIT_SRC_DIR="$TMP_DIR/git-src"
ASSET_DIR="$PROJECT_DIR/app/src/main/assets/native-git/arm64-v8a" JNI_LIB_DIR="$PROJECT_DIR/app/src/main/jniLibs/arm64-v8a"
log() { log() {
printf '\n[%s] %s\n' "cross-compile" "$1" printf '\n[%s] %s\n' "cross-compile" "$1"
@@ -88,12 +88,12 @@ main() {
readelf -h git | sed -n '1,20p' readelf -h git | sed -n '1,20p'
readelf -d git | sed -n '1,40p' readelf -d git | sed -n '1,40p'
mkdir -p "$ASSET_DIR" mkdir -p "$JNI_LIB_DIR"
llvm-strip -s git -o "$ASSET_DIR/git" llvm-strip -s git -o "$JNI_LIB_DIR/libgit.so"
chmod 755 "$ASSET_DIR/git" chmod 755 "$JNI_LIB_DIR/libgit.so"
log "Bundled stripped binary at: $ASSET_DIR/git" log "Bundled stripped binary at: $JNI_LIB_DIR/libgit.so"
ls -lh "$ASSET_DIR/git" ls -lh "$JNI_LIB_DIR/libgit.so"
} }
main "$@" main "$@"

View File

@@ -11,8 +11,8 @@ android {
applicationId = "com.kawomi.githugandroid" applicationId = "com.kawomi.githugandroid"
minSdk = 26 minSdk = 26
targetSdk = 34 targetSdk = 34
versionCode = 10 versionCode = 11
versionName = "0.1.9" versionName = "0.1.10"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

View File

@@ -2,6 +2,7 @@ package com.kawomi.githugandroid
import android.os.Build import android.os.Build
import android.content.Context import android.content.Context
import android.content.pm.ApplicationInfo
import java.io.File import java.io.File
class GitRepositoryRuntime(private val context: Context) { class GitRepositoryRuntime(private val context: Context) {
@@ -9,7 +10,7 @@ class GitRepositoryRuntime(private val context: Context) {
private val extractedGitDir = File(context.filesDir, "native-git/bin") private val extractedGitDir = File(context.filesDir, "native-git/bin")
fun startupBanner(): String { fun startupBanner(): String {
return if (ensureNativeGitBinary() != null) { return if (nativeGitBinary() != null) {
"Welcome to GitHug Android. Native Git prototype ready." "Welcome to GitHug Android. Native Git prototype ready."
} else { } else {
"Welcome to GitHug Android. Native Git binary not bundled for this ABI yet; using in-memory fallback." "Welcome to GitHug Android. Native Git binary not bundled for this ABI yet; using in-memory fallback."
@@ -17,7 +18,7 @@ class GitRepositoryRuntime(private val context: Context) {
} }
fun prepareLevel(level: Level): RepoState { fun prepareLevel(level: Level): RepoState {
val nativeGit = ensureNativeGitBinary() val nativeGit = nativeGitBinary()
if (nativeGit == null) { if (nativeGit == null) {
return level.setup() return level.setup()
} }
@@ -52,7 +53,7 @@ class GitRepositoryRuntime(private val context: Context) {
} }
fun execute(level: Level, currentRepo: RepoState, command: String): Pair<RepoState, List<String>> { fun execute(level: Level, currentRepo: RepoState, command: String): Pair<RepoState, List<String>> {
val nativeGit = ensureNativeGitBinary() val nativeGit = nativeGitBinary()
if (nativeGit == null) { if (nativeGit == null) {
return GitSandboxEngine.execute(currentRepo, command) return GitSandboxEngine.execute(currentRepo, command)
} }
@@ -78,7 +79,8 @@ class GitRepositoryRuntime(private val context: Context) {
return buildList { return buildList {
addAll(GitSandboxEngine.commandReferenceLines()) addAll(GitSandboxEngine.commandReferenceLines())
add("Native Git prototype:") add("Native Git prototype:")
add(" extracted binary path: files/native-git/bin/git") add(" preferred binary path: nativeLibraryDir/libgit.so")
add(" fallback binary path: files/native-git/bin/git")
add(" selected ABI: ${Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"}") add(" selected ABI: ${Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"}")
add(" helper commands: ls, pwd, cat, touch, mkdir, rm, echo") add(" helper commands: ls, pwd, cat, touch, mkdir, rm, echo")
} }
@@ -132,7 +134,7 @@ class GitRepositoryRuntime(private val context: Context) {
private fun inspectSandbox(level: Level): RepoState { private fun inspectSandbox(level: Level): RepoState {
val sandbox = sandboxDir(level) val sandbox = sandboxDir(level)
val nativeGit = ensureNativeGitBinary() val nativeGit = nativeGitBinary()
val filesOnDisk = sandbox.listFiles() val filesOnDisk = sandbox.listFiles()
?.filter { it.isFile && it.name != ".git" } ?.filter { it.isFile && it.name != ".git" }
.orEmpty() .orEmpty()
@@ -180,7 +182,22 @@ class GitRepositoryRuntime(private val context: Context) {
) )
} }
private fun ensureNativeGitBinary(): File? { private fun nativeGitBinary(): File? {
val packaged = packagedNativeGitBinary()
if (packaged != null) {
return packaged
}
return ensureExtractedAssetGitBinary()
}
private fun packagedNativeGitBinary(): File? {
val nativeLibraryDir = context.applicationInfo.nativeLibraryDir ?: return null
val candidate = File(nativeLibraryDir, "libgit.so")
return candidate.takeIf { it.exists() && it.canExecute() }
}
private fun ensureExtractedAssetGitBinary(): File? {
val extracted = File(extractedGitDir, "git") val extracted = File(extractedGitDir, "git")
if (extracted.exists() && extracted.canExecute()) { if (extracted.exists() && extracted.canExecute()) {
return extracted return extracted

Binary file not shown.