[Android Studio] kbalajinagaraj:
Hi your guide is really helpful,

I have executed the steps but cannot get the root access even though the logs are expected as you have posted:

More details:

Android Studio 4.2.1

Build #AI-202.7660.26.42.7351085, built on May 10, 2021

Runtime version: 11.0.8+10-b944.6916264 x86_64

VM: OpenJDK 64-Bit Server VM by N/A

GC: G1 Young Generation, G1 Old Generation

Memory: 2048M

Cores: 12

Registry: external.system.auto.import.disabled=true

Non-Bundled Plugins: org.jetbrains.kotlin

Magisk Version: Stable 22.1

Emulator Version (Emulator--> Extended Controls--> Emulator Version): 30.6.5-7324830

HAXM / KVM Version: HVF 11.4.0

Android SDK Tools: 26.1.1

Host Operating System: macOS 11.4

Terminal input & output:

[!] and we are NOT in an emulator shell

[*] Set Directorys

[-] Test if ADB SHELL is working

[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell

[-] Magisk installer Zip exists already

[*] Cleaning up the ADB working space

[*] Creating the ADB working space

[*] Push Magisk.zip into /data/data/com.android.shell/Magisk

[-] ./Magisk.zip: 1 file pushed, 0 skipped. 164.7 MB/s (7513409 bytes in 0.043s)

[*] create Backup File of ramdisk.img

[*] Push ramdisk.img into /data/data/com.android.shell/Magisk

[-] /Users/bkumar1/Library/Android/sdk/system-images/android-29/polestar_emulator/x86_64/ramdisk.img: 1 file pushed, 0 skipped. 59.8 MB/s (884032 bytes in 0.014s)

[*] Push rootAVD.sh into /data/data/com.android.shell/Magisk

[-] rootAVD.sh: 1 file pushed, 0 skipped. 537.2 MB/s (1996068 bytes in 0.004s)

[-] run the actually Boot/Ramdisk/Kernel Image Patch Script

[*] from Magisk by topjohnwu and modded by NewBit XDA

[!] We are in an emulator shell

[-] Switch to the location of the script file

[*] Extracting busybox and Magisk.zip ...

[-] Checking AVDs Internet connection...

[!] AVD is online

[!] Checking available Magisk Versions

[?] Choose a Magisk Version to install and make it local

[1] Local '22.0' (ENTER)

[2] Canary f822ca5b(23001)

[3] Stable 23.0

[1] You choose Magisk Local Version '22.0'

[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH

[!] We are in an emulator shell

[-] We are now in Magisk Busybox STANDALONE (D)ASH

[*] rootAVD with Magisk '22.0' Installer

[-] Get Flags

[*] System-as-root, keep dm/avb-verity

[-] Encrypted data, keep forceencrypt

[*] RECOVERYMODE=false

[-] KEEPVERITY=true

[*] KEEPFORCEENCRYPT=true

[-] Api Level Arch Detect

[-] Device Platform: x64

[-] Device SDK API: 29

[-] ARCH32 x86

[-] First API Level: 28

[*] copy all files from /data/data/com.android.shell/Magisk/lib/x86 to /data/data/com.android.shell/Magisk

[*] Detecting ramdisk.img compression

[!] Ramdisk.img uses gzip compression

[-] taken from shakalaca's MagiskOnEmulator/process.sh

[*] executing ramdisk splitting / extraction / repacking

[*] After decompressing ramdisk.img, magiskboot will work

Detected format: [gzip]

[-] Test patch status and do restore

[-] Checking ramdisk status

[-] STATUS=0

[-] Stock boot image detected

[-] Patching ramdisk

[*] adding overlay.d/sbin folders to ramdisk

Loading cpio: [ramdisk.cpio]

Create directory [overlay.d] (0750)

Create directory [overlay.d/sbin] (0750)

Dump cpio: [ramdisk.cpio]

[!] PATCHFSTAB=false

[!] Skipping fstab.ranchu patch with /dev/block/sda

[?] If you want fstab.ranchu patched, Call rootAVD with PATCHFSTAB

[!] AddRCscripts=false

[!] Skip adding *.rc scripts into ramdisk.img/sbin/*.rc

[?] If you want *.rc scripts added into ramdisk.img/sbin/*.rc, Call rootAVD with AddRCscripts

[!] patching the ramdisk with Magisk Init

Loading cpio: [ramdisk.cpio]

Add entry [init] (0750)

Add entry [overlay.d/sbin/magisk32.xz] (0644)

Add entry [overlay.d/sbin/magisk64.xz] (0644)

Patch with flag KEEPVERITY=[true] KEEPFORCEENCRYPT=[true]

Loading cpio: [ramdisk.cpio.orig]

Backup mismatch entry: [init] -> [.backup/init]

Record new entry: [overlay.d] -> [.backup/.rmlist]

Record new entry: [overlay.d/sbin] -> [.backup/.rmlist]

Record new entry: [overlay.d/sbin/magisk32.xz] -> [.backup/.rmlist]

Record new entry: [overlay.d/sbin/magisk64.xz] -> [.backup/.rmlist]

Create directory [.backup] (0000)

Add entry [.backup/.magisk] (0000)

Dump cpio: [ramdisk.cpio]

[*] repacking back to ramdisk.img format

[!] Rename Magisk.zip to Magisk.apk

[*] Pull ramdiskpatched4AVD.img into ramdisk.img

[-] /data/data/com.android.shell/Magisk/ramdiskpatched4AVD.img: 1 file pulled, 0 skipped. 95.5 MB/s (1476190 bytes in 0.015s)

[*] Pull Magisk.apk into

[-] /data/data/com.android.shell/Magisk/Magisk.apk: 1 file pulled, 0 skipped. 260.2 MB/s (7513409 bytes in 0.028s)

[-] Clean up the ADB working space

[-] Install all APKs placed in the Apps folder

[*] Trying to install Apps/Magisk.apk

Performing Streamed Install

Success

[-] Shut-Down & Reboot the AVD and see if it worked

[-] Root and Su with Magisk for Android Studio AVDs

[-] Modded by NewBit XDA - Jan. 2021

[!] Huge Credits and big Thanks to topjohnwu and shakalaca

___

Question:

After executing this, I restarted the AVD and opened again - but I cannot get the root level access from this.

I reopened AVD again and saw Cold boot emulator engine failed in the top.

Did I miss anything - any help would be highly appreciated. Thank you.