Edxposed research Magisk source code download and compile a detailed practical tutorial

Note: The operations in this article are implemented on the Windows platform.

1. Magisk source code download

In the terminal, execute the following git command to download the Magisk source code.

E:\workspace\androidstudio\EdXposedProj\20210109>git clone --recurse-submodules https://github.com/topjohnwu/Magisk.git

After the above command is executed, the pcre module will fail to download. This is because the submodule " pcre " of Magisk is downloaded from " https://android.googlesource.com/ ", and " https://android.googlesource.com/ " cannot be accessed in China . The solution is to change the download address to Tsinghua source.

(1) Modify the download url of .gitmodules in the root directory of Magisk source code.

The file path is:

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk\.gitmodules

Before modification:

...省略
[submodule "pcre"]
 path = native/jni/external/pcre
 url = https://android.googlesource.com/platform/external/pcre
...省略

after modification:

...省略
[submodule "pcre"]
 path = native/jni/external/pcre
 url = https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/external/pcre
...省略

(2) Modify the download url of the config file in the .git directory of the Magisk source code root directory.

The file path is:

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk\.git\config

Before modification:

...省略
[submodule "pcre"]
 url = https://android.googlesource.com/platform/external/pcre
[submodule "selinux"]re
...省略

after modification:

...省略
[submodule "pcre"]
 url = https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/external/pcre
...省略

(3), execute the git submodule command in the Magisk source code root directory to download the submodule

The reference command is as follows:

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk>git submodule update --init --recursive
Submodule path 'native/jni/external/pcre': checked out '986dc24ace8aea66189a95510813747155fa3800'

After the source code synchronization is completed, you can use android studio to load the Magisk project source code. If there is a problem during the synchronization process, you can refer to the following article to configure the maven download source:

The solution to slow download of gradle files in Android Studio for young people who don’t talk about martial arts

Two, source code compilation environment configuration

(1) Install python 3.7 and above, and add python to the system PATH environment variable. For example, the python path:

C:\Users\Qiang\AppData\Local\Programs\Python\Python37

The python path is added to the PATH environment variable as shown below:

image

(2) Install JDK and configure the path of bin in jdk to the system PATH environment variable, such as jdk bin path:

C:\Program Files\Java\jdk1.8.0_74\bin

After jdk bin is added to the PATH environment variable, it looks like this:

image

(3) Add the environment variable ANDROID_SDK_ROOT, and set the value to the SDK path configured by android studio.

After Magisk synchronization is completed, the SDK path can be obtained in the Magisk project root directory file "local.properties", such as the possible SDK path configuration of local.properties:

...省略
sdk.dir=C\:\\Users\\Qiang\\AppData\\Local\\Android\\Sdk
...省略

After configuration, as shown in the figure below:

image

Three, compile the Magisk project

Before compiling, first open the Magisk project with Android studio . And open the Android Studio  " Terminal " terminal, and switch to the Magisk source code root directory in the terminal . As follows:

image

 

The script " build.py " is provided in the Magisk project to build the Magisk module, and the terminal executes the " build.py " command to view the provided compilation command parameters. As follows:

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk>build.py
usage: build.py [-h] [-r] [-v] [-c CONFIG]
                {all,binary,app,stub,snet,zip,uninstaller,clean,ndk} ...

Magisk build script

optional arguments:
  -h, --help            show this help message and exit
  -r, --release         compile in release mode
  -v, --verbose         verbose output
  -c CONFIG, --config CONFIG
                        custom config file (default: config.prop)

actions:
  {all,binary,app,stub,snet,zip,uninstaller,clean,ndk}
    all                 build binaries, apks, zips
    binary              build binaries
    app                 build Magisk Manager
    stub                build stub Magisk Manager
    snet                build snet extension
    zip                 zip Magisk into a flashable zip
    uninstaller         create flashable uninstaller
    clean               cleanup
    ndk                 setup Magisk NDK

(1) If it is the first time to compile, execute the following command to install the "ndk" compiling environment.

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk>build.py ndk

* Downloading android-ndk-r21d-windows-x86_64.zip

After the execution is complete, ndk will be installed to the root directory pointed to by ANDROID_SDK_ROOT . As follows:

 

image

 

image

(2) Execute the following commands to compile Magisk related modules

E:\workspace\androidstudio\EdXposedProj\20210109\Magisk>build.py all

* Building Magisk Manager stub

After the compilation is complete, you can see the generated Magisk flashing package in the out file of the Magisk project root directory. As follows:

image

After the Magisk flashing package is compiled, you can use twrp to flash to the mobile device. You can refer to the following article for Magisk flashing into the phone:

Edxposed learning research (1) teach you how to install Edxposed

 

Previous articleEdxposed learning research (3) install Edxposed without Magisk using adb command

Edxposed learning research related articles:

Edxposed learning research (1) teach you how to install Edxposed

Edxposed learning research (2) hand-by-hand compiling the source code of Riru and Edxposed projects

Edxposed learning research (3) free Magisk to use adb command to install Edxposed

 

Reading the shared articles every day is your greatest support. Those big guys who haven't paid attention to the WeChat public account will pay attention before leaving. We will share wonderful articles such as security research, Android system source code customization and development every day.image

image

Guess you like

Origin blog.csdn.net/u011426115/article/details/112936921