Commit c6d2bf57 authored by topjohnwu's avatar topjohnwu

Massive building system rewrite

parent 25703c17
...@@ -2,9 +2,10 @@ out ...@@ -2,9 +2,10 @@ out
*.zip *.zip
*.jks *.jks
*.apk *.apk
config.prop
# Built binaries # Built binaries
ziptools/zipadjust native/out
# Android Studio / Gradle # Android Studio / Gradle
*.iml *.iml
......
# Magisk # Magisk
## How to build Magisk ## Building Environment Requirements
#### Building has been tested on 3 major platforms: macOS, Ubuntu, Windows 10
### Environment Requirements
1. Python 3.5+: run `build.py` script 1. Python 3.5+: run `build.py` script
2. Java Development Kit (JDK) 8: Compile Magisk Manager and sign zips 2. Java Development Kit (JDK) 8: Compile Magisk Manager and sign zips
3. Latest Android SDK: `ANDROID_HOME` environment variable should point to the Android SDK folder 3. Latest Android SDK: set `ANDROID_HOME` environment variable to the path to Android SDK
4. Android NDK: Install NDK along with SDK (`$ANDROID_HOME/ndk-bundle`), or specify custom path `ANDROID_NDK` 4. Android NDK: Install NDK along with SDK (`$ANDROID_HOME/ndk-bundle`), or optionally specify a custom path `ANDROID_NDK`
5. (Windows Only) Python package Colorama: Install with `pip install colorama`, used for ANSI color codes 5. (Windows Only) Python package Colorama: Install with `pip install colorama`, used for ANSI color codes
### Instructions and Notes ## Building Notes and Instructions
1. Magisk can be built with the latest NDK (r16 as of writing), however binaries released officially will be built with NDK r10e due to ELF incompatibilities with the binaries built from the newer NDKs. 1. Building is tested on macOS, Ubuntu, and Windows 10 using the latest stable NDK and NDK r10e. Officially released binaries were built with NDK r10e.
2. The easiest way to setup the environment is by importing the folder as an Android Studio project. The IDE will download required components and construct the environment for you. You still have to set the `ANDROID_HOME` environment variable to point to the SDK path. 2. Set configurations in `config.prop`. A sample file `config.prop.sample` is provided as an example.
3. Run `build.py` with argument `-h` to see the built-in help message. The `-h` option also works for each supported actions, e.g. `./build.py binary -h` 3. Run `build.py` with argument `-h` to see the built-in help message. The `-h` option also works for each supported actions, e.g. `./build.py binary -h`
4. Build everything with `build.py`, don't directly call `gradlew` or `ndk-build`, since most requires special setup / dependencies. 4. By default, `build.py` will build binaries and Magisk Manager in debug mode. If you want to build Magisk Manager in release mode (through the `--release` flag), you will need to place a Java Keystore file at `release-key.jks` to sign Magisk Manager's APK. For more information, check out [Google's Official Documentation](https://developer.android.com/studio/publish/app-signing.html#signing-manually).
5. By default, `build.py` will build binaries and Magisk Manager in debug mode. If you want to build Magisk Manager in release mode (through the flag `--release`), you will need to place a Java Keystore file at `release_signature.jks` to sign Magisk Manager's APK. For more information, check out [Google's Official Documentation](https://developer.android.com/studio/publish/app-signing.html#signing-manually).
## License ## License
......
This diff is collapsed.
# The version string and version code of Magisk
version=
versionCode=
outdir=out
# Whether use pretty names for zips, e.g. Magisk-v${version}.zip, Magisk-uninstaller-${date}.zip
# The default output names are magisk-${release/debug/uninstaller}.zip
prettyName=false
# These pwds are passed to apksigner for release-key.jks. Necessary when building release apks
keyStorePass=
keyPass=
...@@ -13,8 +13,9 @@ android { ...@@ -13,8 +13,9 @@ android {
defaultConfig { defaultConfig {
externalNativeBuild { externalNativeBuild {
ndkBuild { ndkBuild {
// Passes an optional argument to ndk-build. // Pass arguments to ndk-build.
arguments "GRADLE=true" arguments('B_MAGISK=true', 'B_INIT=true', 'B_BOOT=true', 'MAGISK_VERSION=debug',
'MAGISK_VER_CODE=99999', 'MAGISK_DEBUG=-DMAGISK_DEBUG')
} }
} }
} }
......
...@@ -23,7 +23,7 @@ UTIL_SRC := utils/cpio.c \ ...@@ -23,7 +23,7 @@ UTIL_SRC := utils/cpio.c \
# Binaries # Binaries
######################## ########################
ifneq "$(or $(PRECOMPILE), $(GRADLE))" "" ifdef B_MAGISK
# magisk main binary # magisk main binary
include $(CLEAR_VARS) include $(CLEAR_VARS)
...@@ -57,13 +57,14 @@ LOCAL_SRC_FILES := \ ...@@ -57,13 +57,14 @@ LOCAL_SRC_FILES := \
su/su_socket.c \ su/su_socket.c \
$(UTIL_SRC) $(UTIL_SRC)
LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX ${MAGISK_DEBUG} \
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
LOCAL_LDLIBS := -llog LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif endif
ifndef PRECOMPILE ifdef B_INIT
# magiskinit # magiskinit
include $(CLEAR_VARS) include $(CLEAR_VARS)
...@@ -72,7 +73,7 @@ LOCAL_STATIC_LIBRARIES := libsepol liblzma ...@@ -72,7 +73,7 @@ LOCAL_STATIC_LIBRARIES := libsepol liblzma
LOCAL_C_INCLUDES := \ LOCAL_C_INCLUDES := \
jni/include \ jni/include \
jni/magiskpolicy \ jni/magiskpolicy \
../out/$(TARGET_ARCH_ABI) \ out/$(TARGET_ARCH_ABI) \
$(LIBSEPOL) \ $(LIBSEPOL) \
$(LIBLZMA) $(LIBLZMA)
...@@ -87,6 +88,10 @@ LOCAL_SRC_FILES := \ ...@@ -87,6 +88,10 @@ LOCAL_SRC_FILES := \
LOCAL_LDFLAGS := -static LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif
ifdef B_BOOT
# magiskboot # magiskboot
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := magiskboot LOCAL_MODULE := magiskboot
...@@ -113,8 +118,10 @@ LOCAL_CFLAGS := -DXWRAP_EXIT ...@@ -113,8 +118,10 @@ LOCAL_CFLAGS := -DXWRAP_EXIT
LOCAL_LDLIBS := -lz LOCAL_LDLIBS := -lz
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
# static binaries endif
ifndef GRADLE # Do not run gradle sync on these binaries
ifdef B_BXZ
# b64xz # b64xz
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := b64xz LOCAL_MODULE := b64xz
...@@ -123,11 +130,14 @@ LOCAL_C_INCLUDES := $(LIBLZMA) ...@@ -123,11 +130,14 @@ LOCAL_C_INCLUDES := $(LIBLZMA)
LOCAL_SRC_FILES := b64xz.c LOCAL_SRC_FILES := b64xz.c
LOCAL_LDFLAGS := -static LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif
ifdef B_BB
# Busybox # Busybox
include jni/external/busybox/Android.mk include jni/external/busybox/Android.mk
endif
# Precompile
endif endif
######################## ########################
......
APP_ABI := x86 armeabi-v7a APP_ABI := x86 armeabi-v7a
APP_PLATFORM := android-21 APP_PLATFORM := android-21
APP_CFLAGS := $(MAGISK_FLAGS) -std=gnu99 APP_CFLAGS := -std=gnu99
APP_CPPFLAGS := -std=c++11 APP_CPPFLAGS := -std=c++11
APP_SHORT_COMMANDS := true APP_SHORT_COMMANDS := true
LOCAL_PATH:= $(call my-dir) LOCAL_PATH := $(call my-dir)
# libsqlite.so (stub) # libsqlite.so (stub)
include $(CLEAR_VARS) include $(CLEAR_VARS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment