diff --git a/build.py b/build.py index 4cccb0606..b4dea3cab 100755 --- a/build.py +++ b/build.py @@ -55,8 +55,13 @@ if is_windows: if not sys.version_info >= (3, 8): error("Requires Python 3.8+") -if "ANDROID_SDK_ROOT" not in os.environ: - error("Please set Android SDK path to environment variable ANDROID_SDK_ROOT!") +try: + sdk_path = Path(os.environ["ANDROID_HOME"]) +except KeyError: + try: + sdk_path = Path(os.environ["ANDROID_SDK_ROOT"]) + except KeyError: + error("Please set Android SDK path to environment variable ANDROID_HOME") if shutil.which("sccache") is not None: os.environ["RUSTC_WRAPPER"] = "sccache" @@ -80,7 +85,6 @@ default_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"] support_targets = default_targets + ["resetprop"] rust_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"] -sdk_path = Path(os.environ["ANDROID_SDK_ROOT"]) ndk_root = sdk_path / "ndk" ndk_path = ndk_root / "magisk" ndk_build = ndk_path / "ndk-build" diff --git a/docs/build.md b/docs/build.md index 0f21f7075..86e152320 100644 --- a/docs/build.md +++ b/docs/build.md @@ -18,7 +18,7 @@ - On Windows, download the install the latest Git version on the [official website](https://git-scm.com/download/win).
Make sure to **"Enable symbolic links"** during installation. - Install Android Studio and follow the instructions and go through the initial setup. -- Set environment variable `ANDROID_SDK_ROOT` to the Android SDK folder. This path can be found in Android Studio settings. +- Set environment variable `ANDROID_HOME` to the Android SDK folder. This path can be found in Android Studio settings. - Setup JDK: - The recommended option is to set environment variable `ANDROID_STUDIO` to the path where your Android Studio is installed. The build script will automatically find and use the bundled JDK. - You can also setup JDK 17 yourself, but this guide will not cover the instructions. @@ -40,7 +40,7 @@ ### Developing Rust -The Magisk NDK package [ONDK](https://github.com/topjohnwu/ondk) (the one installed with `./build.py ndk`) bundles a complete Rust toolchain, so *building* the Magisk project itself does not require any further configuration. However, if you'd like to work on the Rust codebase with proper support, you'd need some setup as most development tools are built around `rustup`. +The Magisk NDK package [ONDK](https://github.com/topjohnwu/ondk) (the one installed with `./build.py ndk`) bundles a complete Rust toolchain, so _building_ the Magisk project itself does not require any further configuration. However, if you'd like to work on the Rust codebase with proper support, you'd need some setup as most development tools are built around `rustup`. Let's first setup `rustup` to use our custom ONDK Rust toolchain by default: @@ -49,7 +49,7 @@ Let's first setup `rustup` to use our custom ONDK Rust toolchain by default: ```bash # Link the ONDK toolchain with the name "magisk" -rustup toolchain link magisk "$ANDROID_SDK_ROOT/ndk/magisk/toolchains/rust" +rustup toolchain link magisk "$ANDROID_HOME/ndk/magisk/toolchains/rust" # Set magisk as default rustup default magisk ``` diff --git a/scripts/avd_test.sh b/scripts/avd_test.sh index 8a2a5e26c..3b5542950 100755 --- a/scripts/avd_test.sh +++ b/scripts/avd_test.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -emu="$ANDROID_SDK_ROOT/emulator/emulator" -avd="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager" +set -xe +. scripts/test_common.sh + emu_args_base='-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot' lsposed_url='https://github.com/LSPosed/LSPosed/releases/download/v1.9.2/LSPosed-v1.9.2-7024-zygisk-release.zip' emu_pid= @@ -134,8 +135,8 @@ run_test() { # System image variable and paths local pkg="system-images;android-$ver;$type;$arch" - local img_dir="$ANDROID_SDK_ROOT/system-images/android-$ver/$type/$arch" - local ramdisk="$img_dir/ramdisk.img" + local sys_img_dir="$ANDROID_HOME/system-images/android-$ver/$type/$arch" + local ramdisk="$sys_img_dir/ramdisk.img" # Old Linux kernels will not boot with memory larger than 3GB local memory @@ -181,10 +182,7 @@ run_test() { rm -f magisk_patched.img } -set -xe trap cleanup EXIT -. scripts/test_common.sh - export -f wait_for_boot export -f wait_for_bootanim diff --git a/scripts/cuttlefish.sh b/scripts/cuttlefish.sh index c55a1fa2c..2de9c793b 100755 --- a/scripts/cuttlefish.sh +++ b/scripts/cuttlefish.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +set -xe +. scripts/test_common.sh + cvd_args='-daemon -enable_sandbox=false -memory_mb=8192 -report_anonymous_usage_stats=n' magisk_args='-init_boot_image=magisk_patched.img' @@ -96,9 +99,6 @@ run_test() { rm -f magisk_patched.img* } -set -xe -. scripts/test_common.sh - if [ -z $CF_HOME ]; then print_error "! Environment variable CF_HOME is required" exit 1 diff --git a/scripts/test_common.sh b/scripts/test_common.sh index d6ef66439..9c74b770a 100644 --- a/scripts/test_common.sh +++ b/scripts/test_common.sh @@ -1,6 +1,13 @@ -export PATH="$PATH:$ANDROID_SDK_ROOT/platform-tools" +if [ -z $ANDROID_HOME ]; then + export ANDROID_HOME=$ANDROID_SDK_ROOT +fi + +export PATH="$PATH:$ANDROID_HOME/platform-tools" + +sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" +emu="$ANDROID_HOME/emulator/emulator" +avd="$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" -sdk="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" boot_timeout=600 print_title() {