Unlocking the bootloader
Firstly we need to unlock the bootloader to allow us to flash new images. Go to Settings → System → About phone and tap on Build number 7 times or until you see the message ‘You are now a developer’.
Now go to Settings → System → Developer options and enable USB debugging and OEM unlocking.
adb devices. You should see something like:
List of devices attached 804886 device
This confirms that the phone is connected to the computer. Now run
adb reboot bootloader to reboot the phone into fastboot mode. Alternatively, switch off the phone and turn it on while holding Volume Down. Wait until the phone displays the fastboot screen:
fastboot oem unlock. The phone will display information about unlocking the bootloader and prompt for confirmation. Use the volume up/down buttons to select the appropriate choice, and use the power button to confirm.
Note that doing this will perform a factory reset, erasing all data on the phone. Therefore, I recommend doing this as soon as you unbox the Xiaomi Mi A2 if you intend on rooting it.
The phone should then soon restart, and you will need to reconfigure the phone. This is the appropriate time to accept the update to Android 9.0 if you haven't already.
Then repeat the process at Settings → About phone → Build number to enable developer mode, and enable USB debugging and OEM unlock again under Settings → System → Advanced → Developer options.
Prepare Magisk boot image (bootstrap)
Download the latest release of Magisk Manager, e.g. MagiskManager-v6.1.0.apk, and install it to the phone:
adb install MagiskManager-v6.1.0.apk
Magisk Manager needs a copy of the stock boot ROM, so head to https://en.miui.com/download-353.html and download the stock firmware for the Mi A2. Ensure that the version (e.g. 10.0.2.0) and build number (PDIMIJF) are the same as shown under About phone.
Open this file (e.g. jasmine_global_images_V10.0.2.0.PDIMIFJ_20181206.0000.00_9.0_02b8deeb6d.tgz) and extract the images/boot.img file.
Upload this file to the phone:
adb push boot.img /sdcard/
Now open Magisk Manager and tap Install → Patch Boot Image File and select the boot.img file uploaded to the phone.
If all goes well, this should produce a patched_boot.img ready for use with Magisk. Download this file:
adb pull /sdcard/Download/patched_boot.img
Installing Magisk proper
adb reboot bootloader to again return to fastboot mode, and
fastboot boot patched_boot.img to boot the newly-patched image.
If all goes well, Android should launch normally, and Magisk Manager should show that Magisk has been installed. Note, however, that this is only temporary, so to make it permanent, tap Install → Direct Install (Recommended).
If the installation is successful, you should be able to reboot the phone normally and Magisk will continue to function normally.
At the time of writing, Xposed is not available for Android 9.0, but EdXposed can be used as a replacement for some (but not all) Xposed modules.
Follow the instructions in the Install section of the EdXposed page:
Then install the Xposed Installer as usual and reboot. The Xposed Installer should report that Xposed is installed correctly and allow you to install and manage Xposed modules.