Compare commits
4
Commits
v1.6
..
148b494926
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
148b494926
|
||
|
|
cdba2582fa
|
||
|
|
3068939d93
|
||
|
|
dc6f72bcc5
|
@@ -0,0 +1,3 @@
|
||||
[submodule "isodrive"]
|
||||
path = isodrive
|
||||
url = https://git.shihaam.dev/shihaam/isodrive
|
||||
Generated
+1
@@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/isodrive" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,6 +4,118 @@ plugins {
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
}
|
||||
|
||||
// Build isodrive native binary from submodule (only if binaries are missing)
|
||||
val buildIsodrive by tasks.registering {
|
||||
group = "native"
|
||||
description = "Build isodrive binary for all Android architectures"
|
||||
|
||||
val isodriveDir = rootProject.file("isodrive")
|
||||
val outputDir = file("src/main/assets/bin")
|
||||
val architectures = listOf("arm64-v8a", "armeabi-v7a", "x86_64", "x86")
|
||||
|
||||
// Check if all binaries exist
|
||||
val allBinariesExist = architectures.all { arch ->
|
||||
outputDir.resolve("$arch/isodrive").exists()
|
||||
}
|
||||
|
||||
// Skip if all binaries already exist
|
||||
onlyIf { !allBinariesExist }
|
||||
|
||||
doLast {
|
||||
// Verify submodule is initialized
|
||||
if (!isodriveDir.resolve("src").exists()) {
|
||||
throw GradleException("isodrive submodule not initialized. Run: git submodule update --init")
|
||||
}
|
||||
|
||||
val sourceFiles = listOf(
|
||||
"src/util.cpp",
|
||||
"src/configfsisomanager.cpp",
|
||||
"src/androidusbisomanager.cpp",
|
||||
"src/main.cpp"
|
||||
)
|
||||
val srcs = sourceFiles.joinToString(" ") { "$isodriveDir/$it" }
|
||||
val cflags = "-I$isodriveDir/src/include -static-libstdc++ -Os -s"
|
||||
|
||||
val compilers = mapOf(
|
||||
"arm64-v8a" to "aarch64-linux-android26-clang++",
|
||||
"armeabi-v7a" to "armv7a-linux-androideabi26-clang++",
|
||||
"x86_64" to "x86_64-linux-android26-clang++",
|
||||
"x86" to "i686-linux-android26-clang++"
|
||||
)
|
||||
|
||||
// Check if we're on NixOS (nix-shell available)
|
||||
val useNixShell = File("/etc/NIXOS").exists() ||
|
||||
Runtime.getRuntime().exec(arrayOf("which", "nix-shell")).waitFor() == 0
|
||||
|
||||
if (useNixShell) {
|
||||
println("NixOS detected, using nix-shell for NDK...")
|
||||
|
||||
// Build all architectures in one nix-shell invocation
|
||||
val buildScript = compilers.entries.joinToString("\n") { (arch, compiler) ->
|
||||
val archDir = outputDir.resolve(arch)
|
||||
val output = archDir.resolve("isodrive")
|
||||
if (output.exists()) {
|
||||
"echo 'isodrive for $arch already exists, skipping'"
|
||||
} else {
|
||||
"""
|
||||
mkdir -p "$archDir"
|
||||
echo "Building isodrive for $arch..."
|
||||
"${'$'}TOOLCHAIN/$compiler" $cflags $srcs -o "$output"
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
exec {
|
||||
environment("SRCS", srcs)
|
||||
environment("CFLAGS", cflags)
|
||||
environment("NIXPKGS_ALLOW_UNFREE", "1")
|
||||
commandLine("nix-shell", "-p", "androidenv.androidPkgs.ndk-bundle", "--run", """
|
||||
SDK_ROOT=${'$'}(find /nix/store -maxdepth 1 -name "*android-sdk-ndk*" -type d 2>/dev/null | head -1)
|
||||
NDK=${'$'}(ls -d "${'$'}SDK_ROOT/libexec/android-sdk/ndk/"* | head -1)
|
||||
TOOLCHAIN="${'$'}NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
||||
echo "Using NDK: ${'$'}NDK"
|
||||
$buildScript
|
||||
echo "Done building isodrive"
|
||||
""".trimIndent())
|
||||
}
|
||||
} else {
|
||||
// Standard NDK lookup for non-NixOS
|
||||
val ndkDir = listOfNotNull(
|
||||
System.getenv("ANDROID_NDK_HOME"),
|
||||
System.getenv("ANDROID_NDK")
|
||||
).firstOrNull { File(it).exists() }
|
||||
?: throw GradleException("Android NDK not found. Set ANDROID_NDK_HOME or install NDK via SDK Manager.")
|
||||
|
||||
val toolchain = "$ndkDir/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
||||
if (!File(toolchain).exists()) {
|
||||
throw GradleException("NDK toolchain not found at: $toolchain")
|
||||
}
|
||||
|
||||
compilers.forEach { (arch, compiler) ->
|
||||
val archDir = outputDir.resolve(arch)
|
||||
val output = archDir.resolve("isodrive")
|
||||
|
||||
if (output.exists()) {
|
||||
println("isodrive for $arch already exists, skipping")
|
||||
return@forEach
|
||||
}
|
||||
|
||||
archDir.mkdirs()
|
||||
println("Building isodrive for $arch...")
|
||||
exec {
|
||||
commandLine("sh", "-c", "$toolchain/$compiler $cflags $srcs -o $output")
|
||||
}
|
||||
}
|
||||
println("Done building isodrive")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hook into the build process - build isodrive before merging assets
|
||||
tasks.matching { it.name.startsWith("merge") && it.name.endsWith("Assets") }.configureEach {
|
||||
dependsOn(buildIsodrive)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "sh.sar.isodroid"
|
||||
compileSdk = 36
|
||||
|
||||
@@ -58,42 +58,14 @@ class IsoDriveManager(private val context: Context) {
|
||||
binaryPath = targetFile.absolutePath
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
// Binary not bundled yet, will use system isodrive if available
|
||||
checkSystemBinary()
|
||||
// Binary extraction failed
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkSystemBinary(): Boolean = withContext(Dispatchers.IO) {
|
||||
// Check common locations first (more reliable than 'which')
|
||||
val commonPaths = listOf(
|
||||
"/data/adb/modules/isodrive-magisk/system/bin/isodrive",
|
||||
"/data/adb/modules/isodrive/system/bin/isodrive",
|
||||
"/system/bin/isodrive",
|
||||
"/system/xbin/isodrive",
|
||||
"/data/local/tmp/isodrive",
|
||||
"/vendor/bin/isodrive"
|
||||
)
|
||||
for (path in commonPaths) {
|
||||
val checkResult = RootManager.executeCommand("test -f $path && echo exists")
|
||||
if (checkResult.success && checkResult.output.contains("exists")) {
|
||||
binaryPath = path
|
||||
return@withContext true
|
||||
}
|
||||
}
|
||||
|
||||
// Try 'which' as fallback
|
||||
val result = RootManager.executeCommand("which isodrive 2>/dev/null")
|
||||
if (result.success && result.output.isNotBlank()) {
|
||||
binaryPath = result.output.trim()
|
||||
return@withContext true
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
suspend fun isSupported(): SupportStatus = withContext(Dispatchers.IO) {
|
||||
// First check if binary is available
|
||||
if (binaryPath == null && !extractBinary()) {
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Build isodrive from source for all Android architectures
|
||||
# Requires: Android NDK (or runs via nix-shell on NixOS)
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
ISODRIVE_DIR="/tmp/isodrive"
|
||||
OUTPUT_DIR="$SCRIPT_DIR/app/src/main/assets/bin"
|
||||
|
||||
# Clone isodrive source
|
||||
if [[ -d "$ISODRIVE_DIR" ]]; then
|
||||
echo "Updating isodrive source..."
|
||||
git -C "$ISODRIVE_DIR" pull
|
||||
else
|
||||
echo "Cloning isodrive..."
|
||||
git clone --depth 1 https://github.com/nitanmarcel/isodrive "$ISODRIVE_DIR"
|
||||
fi
|
||||
|
||||
SRCS="$ISODRIVE_DIR/src/util.cpp $ISODRIVE_DIR/src/configfsisomanager.cpp $ISODRIVE_DIR/src/androidusbisomanager.cpp $ISODRIVE_DIR/src/main.cpp"
|
||||
CFLAGS="-I$ISODRIVE_DIR/src/include -static-libstdc++ -Os -s"
|
||||
|
||||
build_all() {
|
||||
local NDK="$1"
|
||||
local TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
||||
|
||||
echo "Building arm64-v8a..."
|
||||
"$TOOLCHAIN/aarch64-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/arm64-v8a/isodrive"
|
||||
|
||||
echo "Building armeabi-v7a..."
|
||||
"$TOOLCHAIN/armv7a-linux-androideabi26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/armeabi-v7a/isodrive"
|
||||
|
||||
echo "Building x86_64..."
|
||||
"$TOOLCHAIN/x86_64-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/x86_64/isodrive"
|
||||
|
||||
echo "Building x86..."
|
||||
"$TOOLCHAIN/i686-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/x86/isodrive"
|
||||
|
||||
echo "Done! Built isodrive for all architectures."
|
||||
ls -la "$OUTPUT_DIR"/*/isodrive
|
||||
}
|
||||
|
||||
# On NixOS, prefer nix-shell (local Android SDK has /bin/bash issues)
|
||||
if command -v nix-shell &>/dev/null; then
|
||||
echo "Using nix-shell to get Android NDK..."
|
||||
export SRCS CFLAGS OUTPUT_DIR
|
||||
NIXPKGS_ALLOW_UNFREE=1 nix-shell -p androidenv.androidPkgs.ndk-bundle --run '
|
||||
SDK_ROOT=$(find /nix/store -maxdepth 1 -name "*android-sdk-ndk*" -type d 2>/dev/null | head -1)
|
||||
NDK=$(ls -d "$SDK_ROOT/libexec/android-sdk/ndk/"* | head -1)
|
||||
TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
||||
|
||||
echo "Using NDK: $NDK"
|
||||
|
||||
echo "Building arm64-v8a..."
|
||||
"$TOOLCHAIN/aarch64-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/arm64-v8a/isodrive"
|
||||
|
||||
echo "Building armeabi-v7a..."
|
||||
"$TOOLCHAIN/armv7a-linux-androideabi26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/armeabi-v7a/isodrive"
|
||||
|
||||
echo "Building x86_64..."
|
||||
"$TOOLCHAIN/x86_64-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/x86_64/isodrive"
|
||||
|
||||
echo "Building x86..."
|
||||
"$TOOLCHAIN/i686-linux-android26-clang++" $CFLAGS $SRCS -o "$OUTPUT_DIR/x86/isodrive"
|
||||
|
||||
echo "Done!"
|
||||
ls -la "$OUTPUT_DIR"/*/isodrive
|
||||
'
|
||||
elif [[ -n "${ANDROID_NDK_HOME:-}" ]]; then
|
||||
build_all "$ANDROID_NDK_HOME"
|
||||
elif [[ -n "${ANDROID_NDK:-}" ]]; then
|
||||
build_all "$ANDROID_NDK"
|
||||
else
|
||||
echo "Error: Android NDK not found."
|
||||
echo "Set ANDROID_NDK_HOME or ANDROID_NDK, or install nix-shell."
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Get the directory where this script lives
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
|
||||
ISODRIVE_VERSION=$(curl -sI https://github.com/nitanmarcel/isodrive-magisk/releases/latest | grep -i ^location | grep -oP 'v\K[\d.]+')
|
||||
curl -sL https://github.com/nitanmarcel/isodrive-magisk/releases/download/v$ISODRIVE_VERSION/isodrive-magisk-v$ISODRIVE_VERSION.zip -o /tmp/isodrive-magisk.zip
|
||||
|
||||
unzip -q /tmp/isodrive-magisk.zip -d /tmp/isodrive-magisk
|
||||
|
||||
# Move the isodrive binary for each architecture
|
||||
mv /tmp/isodrive-magisk/libs/arm64-v8a/isodrive $SCRIPT_DIR/app/src/main/assets/bin/arm64-v8a/
|
||||
mv /tmp/isodrive-magisk/libs/armeabi-v7a/isodrive $SCRIPT_DIR/app/src/main/assets/bin/armeabi-v7a/
|
||||
mv /tmp/isodrive-magisk/libs/x86/isodrive $SCRIPT_DIR/app/src/main/assets/bin/x86/
|
||||
mv /tmp/isodrive-magisk/libs/x86_64/isodrive $SCRIPT_DIR/app/src/main/assets/bin/x86_64/
|
||||
|
||||
# Clean up temp files
|
||||
rm -rf /tmp/isodrive-magisk /tmp/isodrive-magisk.zip
|
||||
Submodule
+1
Submodule isodrive added at 2e9f28bd90
Reference in New Issue
Block a user