pip install colorama to install the colorama python packageANDROID_HOME to the Android SDK folder. This path can be found in Android Studio settings.ANDROID_STUDIO to the path where your Android Studio is installed. The build script will automatically find and use the bundled JDK.git clone --recurse-submodules https://github.com/topjohnwu/Magisk.git./build.py ndk to let the script download and install NDK for you./build.py all../build.py -h to see all available actions. -h to access help (e.g. ./build.py native -h).config.prop. A sample config.prop.sample is provided.sccache or ccache is installed and available in your PATH, build.py will automatically use it to speed up C++ and Rust builds../gradlew, cargo, or ndk-build) with the same environment variables configured by build.py, prefix the command with scripts/env.py (e.g. scripts/env.py ./gradlew :apk:assembleDebug). You can also run ./build.py clippy to lint Rust code or ./build.py cargo ... to invoke Cargo directly against the native workspace../build.py gen (or build all native code with ./build.py native), which generates build flags, C++/Rust FFI bindings, protobuf sources, and native/compile_commands.json for C/C++ language servers.First, install rustup, the official Rust toolchain manager. The Magisk NDK package 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, it’ll be easier if you link ONDK’s Rust toolchain in rustup and set it as default so several development tools and IDEs will work properly:
# Link the ONDK toolchain with the name "magisk"
rustup toolchain link magisk "$ANDROID_HOME/ndk/magisk/toolchains/rust"
# Set magisk as default
rustup default magisk
If you plan to use VSCode, you can then install the rust-analyzer plugin and everything should be good to go. If you plan to use Jetbrain IDEs (e.g. Rustrover, or its Rust Plugin), we need some additional setup:
rustup toolchain install nightly
# Add some components that are also included in ONDK
rustup +nightly component add rust-src clippy
rustup limitations# We choose ~/.cargo/wrapper here as an example (and a good recommendation)
# Pick any path you like, you just need to use this path in the next step
./build.py rustup ~/.cargo/wrapper
rustfmt and use Clippy as the external linter.config.prop.