[SCRIPT] rootAVD - root your Android Studio Virtual Device emulator with Magisk [Android 12][Linux][Darwin/MacOS][WIN][Google Play Store APIs]

Search This thread

newbit

Senior Member
Nov 16, 2008
211
79
Hi! Thanks for answering me. I did read it and tried a lot of things but I just fail to understand it as a "new user". Is there a way you could help me please? There isn't much info about it out there
sure, on which stage do you stuck? Which preconditions did you met? Which not?
 

itandy

Senior Member
Apr 28, 2010
2,378
1,355
Hong Kong
Just tried it on my A12 AVD (x86_64). Everything looks fine. But in the end, the AVD fails to launch anymore.

Screenshot 2022-04-14 200546.png


Log:
Code:
T:\rootAVD-master>rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-31\google_apis\x86_64\ramdisk.img
[*] Set Directorys
[-] Test if ADB SHELL is working
[-] ADB connectoin possible
[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
[*] looking for Magisk installer Zip
[*] Cleaning up the ADB working space
[*] Creating the ADB working space
[*] Push Magisk.zip into /data/data/com.android.shell/Magisk
[-] T:\rootAVD-master\Magisk.zip: 1 file pushed, 0 skipped. 162.4 MB/s (10641074 bytes in 0.063s)
[*] create Backup File
[*] Push ramdisk.img into /data/data/com.android.shell/Magisk
[-] C:\Users\andy\AppData\Local\Android\Sdk\system-images\android-31\google_apis\x86_64\ramdisk.img: 1 file pushed, 0 skipped. 226.7 MB/s (3663956 bytes in 0.015s)
[-] Copy rootAVD Script into Magisk DIR
rootAVD.sh: 1 file pushed, 0 skipped. 113.8 MB/s (7847625 bytes in 0.066s)
[-] run the actually Boot/Ramdisk/Kernel Image Patch Script
[*] from Magisk by topjohnwu and modded by NewBit XDA
[!] We are in a ranchu emulator shell
[-] Api Level Arch Detect
[-] Device Platform is x64 only
[-] Device SDK API: 31
[-] First API Level: 31
[-] 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
[!] (s)how all available Magisk Versions
[1] local stable '24.1' (ENTER)
[2] stable 24.3
[3] canary 63a89d9f(24306)
[4] alpha 79f0f323-alpha(24306)
[-] You choose Magisk stable Version '24.1'
[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH
[-] We are now in Magisk Busybox STANDALONE (D)ASH
[*] rootAVD with Magisk '24.1' Installer
[-] Get Flags
[*] System-as-root, keep dm/avb-verity
[-] Encrypted data, keep forceencrypt
[*] RECOVERYMODE=false
[-] KEEPVERITY=true
[*] KEEPFORCEENCRYPT=true
[-] copy all x86_64 files from /data/data/com.android.shell/Magisk/lib/x86_64 to /data/data/com.android.shell/Magisk
[*] Detecting ramdisk.img compression
[!] Ramdisk.img uses lz4_legacy compression
[-] taken from shakalaca's MagiskOnEmulator/process.sh
[*] executing ramdisk splitting / extraction / repacking
[-] API level greater then 30
[*] Check if we need to repack ramdisk before patching ..
[-] Multiple cpio archives detected
[*] Unpacking ramdisk ..
[*] Searching for the real End of the 1st Archive
[-] Dumping from 0 to 1691806 ..
Detected format: [lz4_legacy]
[-] Dumping from 1691806 to 3663937 ..
Detected format: [lz4_legacy]
[*] Repacking ramdisk ..
[-] 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/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/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. 105.4 MB/s (4158011 bytes in 0.038s
[*] Pull Magisk.apk into
[-] /data/data/com.android.shell/Magisk/Magisk.apk: 1 file pulled, 0 skipped. 108.8 MB/s (10641074 bytes in 0.093s
[-] 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 and Reboot [Cold Boot Now] 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, shakalaca and vvb2060
[-] Trying to shut down the AVD
[!] If the AVD doesnt shut down, try it manually!
 

newbit

Senior Member
Nov 16, 2008
211
79
Just tried it on my A12 AVD (x86_64). Everything looks fine. But in the end, the AVD fails to launch anymore.

View attachment 5587949

Log:
Code:
T:\rootAVD-master>rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-31\google_apis\x86_64\ramdisk.img
[*] Set Directorys
[-] Test if ADB SHELL is working
[-] ADB connectoin possible
[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
[*] looking for Magisk installer Zip
[*] Cleaning up the ADB working space
[*] Creating the ADB working space
[*] Push Magisk.zip into /data/data/com.android.shell/Magisk
[-] T:\rootAVD-master\Magisk.zip: 1 file pushed, 0 skipped. 162.4 MB/s (10641074 bytes in 0.063s)
[*] create Backup File
[*] Push ramdisk.img into /data/data/com.android.shell/Magisk
[-] C:\Users\andy\AppData\Local\Android\Sdk\system-images\android-31\google_apis\x86_64\ramdisk.img: 1 file pushed, 0 skipped. 226.7 MB/s (3663956 bytes in 0.015s)
[-] Copy rootAVD Script into Magisk DIR
rootAVD.sh: 1 file pushed, 0 skipped. 113.8 MB/s (7847625 bytes in 0.066s)
[-] run the actually Boot/Ramdisk/Kernel Image Patch Script
[*] from Magisk by topjohnwu and modded by NewBit XDA
[!] We are in a ranchu emulator shell
[-] Api Level Arch Detect
[-] Device Platform is x64 only
[-] Device SDK API: 31
[-] First API Level: 31
[-] 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
[!] (s)how all available Magisk Versions
[1] local stable '24.1' (ENTER)
[2] stable 24.3
[3] canary 63a89d9f(24306)
[4] alpha 79f0f323-alpha(24306)
[-] You choose Magisk stable Version '24.1'
[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH
[-] We are now in Magisk Busybox STANDALONE (D)ASH
[*] rootAVD with Magisk '24.1' Installer
[-] Get Flags
[*] System-as-root, keep dm/avb-verity
[-] Encrypted data, keep forceencrypt
[*] RECOVERYMODE=false
[-] KEEPVERITY=true
[*] KEEPFORCEENCRYPT=true
[-] copy all x86_64 files from /data/data/com.android.shell/Magisk/lib/x86_64 to /data/data/com.android.shell/Magisk
[*] Detecting ramdisk.img compression
[!] Ramdisk.img uses lz4_legacy compression
[-] taken from shakalaca's MagiskOnEmulator/process.sh
[*] executing ramdisk splitting / extraction / repacking
[-] API level greater then 30
[*] Check if we need to repack ramdisk before patching ..
[-] Multiple cpio archives detected
[*] Unpacking ramdisk ..
[*] Searching for the real End of the 1st Archive
[-] Dumping from 0 to 1691806 ..
Detected format: [lz4_legacy]
[-] Dumping from 1691806 to 3663937 ..
Detected format: [lz4_legacy]
[*] Repacking ramdisk ..
[-] 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/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/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. 105.4 MB/s (4158011 bytes in 0.038s
[*] Pull Magisk.apk into
[-] /data/data/com.android.shell/Magisk/Magisk.apk: 1 file pulled, 0 skipped. 108.8 MB/s (10641074 bytes in 0.093s
[-] 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 and Reboot [Cold Boot Now] 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, shakalaca and vvb2060
[-] Trying to shut down the AVD
[!] If the AVD doesnt shut down, try it manually!
That's a very well known and common issue with the emulator binary itself. It doesn't get terminated
and stuck as a process somewhere in the background. Try to find it in the Task-Manager and kill it.
It is called Qemu-whatsoever.exe, it is usually grouped with the Android Studio processes.
 
  • Like
Reactions: itandy

itandy

Senior Member
Apr 28, 2010
2,378
1,355
Hong Kong
That's a very well known and common issue with the emulator binary itself. It doesn't get terminated
and stuck as a process somewhere in the background. Try to find it in the Task-Manager and kill it.
It is called Qemu-whatsoever.exe, it is usually grouped with the Android Studio processes.
It works! You're awesome! Thanks!
 
  • Like
Reactions: newbit

fontaipi

New member
Apr 14, 2022
1
0
Lille
Hi first thanks for your guide,

I'm trying to enable -usb-passthrough on Windows and I got an error running your script.

OS : Windows 11
Emulator : Pixel 5 - API 31
adb root - OK

Code:
❯ .\rootAVD.bat C:\PROGRA~2\Android\android-sdk\system-images\android-31\default\x86_64\ramdisk.img PATCHFSTAB GetUSBHPmodZ
[*] Set Directorys
[-] Test if ADB SHELL is working
[-] ADB connectoin possible
[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
[*] looking for Magisk installer Zip
[*] Cleaning up the ADB working space
[*] Creating the ADB working space
[*] Push Magisk.zip into /data/data/com.android.shell/Magisk
[-] C:\Users\pfontaine\workspace\rootAVD\Magisk.zip: 1 file pushed, 0 skipped. 37.9 MB/s (17930822 bytes in 0.452s)
[*] create Backup File
Access is denied.
[*] Push ramdisk.img into /data/data/com.android.shell/Magisk
[-] C:\PROGRA~2\Android\android-sdk\system-images\android-31\default\x86_64\ramdisk.img: 1 file pushed, 0 skipped. 181.9 MB/s (4106161 bytes in 0.022s)
[-] Copy rootAVD Script into Magisk DIR
rootAVD.sh: 1 file pushed, 0 skipped. 129.9 MB/s (7847625 bytes in 0.058s)
[-] run the actually Boot/Ramdisk/Kernel Image Patch Script
[*] from Magisk by topjohnwu and modded by NewBit XDA
[!] We are in a ranchu emulator shell
[-] Api Level Arch Detect
[-] Device Platform is x64 only
[-] Device SDK API: 31
[-] First API Level: 31
[-] Switch to the location of the script file
[*] Extracting busybox and Magisk.zip ...
[-] Checking AVDs Internet connection...
[!] AVD is online
[!] Checking available Magisk Versions
wget: short read, have only 30
[?] Choose a Magisk Version to install and make it local
[!] (s)how all available Magisk Versions
[1] local stable 'cc79a96f'(24307) (ENTER)
[2] stable 24.3
[3] canary cc79a96f(24307)
[4] alpha a32c4561-alpha(24307)
3
[-] You choose Magisk alpha Version cc79a96f(24307)
[*] Deleting local Magisk 'cc79a96f'(24307)
[*] Downloading Magisk alpha cc79a96f(24307)
wget: got bad TLS record (len:2019) while expecting encrypted data
 03 03 40 18 00 00 00 00 00 00 04 82 05 ab a3 12 fb f2 f0 ec ec b0 bf 82 37 31 50 56 bd 4f 09 9c 36 d0 13 39 b5 7f e0 ec 85 f8 00 a7 e1 33 ad 07 64 8c 73 39 7d da d8 8d 41 bb 7d 0c 4b 1a 48 da d5 d0 7e b7 06 6a 79 9a 2a 9b d9 d2 55 9e ea 3b b5 24 c3 15 f1 92 bd 72 f3 aa e4 a3 76 04 5d 24 c7 b1 f6
wget: connection closed prematurely
[!] Error while downloading Magisk alpha cc79a96f(24307)
[-] patching it together
[!] Downloading Magisk alpha cc79a96f(24307) complete!
[-] Switch to the location of the script file
[*] Extracting busybox and Magisk.zip ...
[*] Downloading USB HOST Permissions Module Zip
[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH
[-] We are now in Magisk Busybox STANDALONE (D)ASH
[*] rootAVD with Magisk cc79a96f(24307) Installer
[-] Get Flags
[*] System-as-root, keep dm/avb-verity
[-] Encrypted data, keep forceencrypt
[*] RECOVERYMODE=false
[-] KEEPVERITY=true
[*] KEEPFORCEENCRYPT=true
[-] copy all x86_64 files from /data/data/com.android.shell/Magisk/lib/x86_64 to /data/data/com.android.shell/Magisk
[*] Detecting ramdisk.img compression
[!] Ramdisk.img uses lz4_legacy compression
[-] taken from shakalaca's MagiskOnEmulator/process.sh
[*] executing ramdisk splitting / extraction / repacking
[-] API level greater then 30
[*] Check if we need to repack ramdisk before patching ..
[*] After decompressing ramdisk.img, magiskboot will work
Detected format: [lz4_legacy]
[-] Test patch status and do restore
[-] Checking ramdisk status
[-] STATUS=1
[-] Magisk patched boot image detected
[-] Constructing environment - PAY ATTENTION to the AVDs Screen
[!] we are root
su: invalid uid/gid '-c'
[!] not root yet
[!] Couldn't construct environment
[!] Double Check Root Access
[!] Re-Run Script with clean ramdisk.img and try again
[!] aborting the script

Any ideas ?
 

newbit

Senior Member
Nov 16, 2008
211
79
Hi first thanks for your guide,

I'm trying to enable -usb-passthrough on Windows and I got an error running your script.

OS : Windows 11
Emulator : Pixel 5 - API 31
adb root - OK

Code:
❯ .\rootAVD.bat C:\PROGRA~2\Android\android-sdk\system-images\android-31\default\x86_64\ramdisk.img PATCHFSTAB GetUSBHPmodZ
[*] Set Directorys
[-] Test if ADB SHELL is working
[-] ADB connectoin possible
[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
[*] looking for Magisk installer Zip
[*] Cleaning up the ADB working space
[*] Creating the ADB working space
[*] Push Magisk.zip into /data/data/com.android.shell/Magisk
[-] C:\Users\pfontaine\workspace\rootAVD\Magisk.zip: 1 file pushed, 0 skipped. 37.9 MB/s (17930822 bytes in 0.452s)
[*] create Backup File
Access is denied.
[*] Push ramdisk.img into /data/data/com.android.shell/Magisk
[-] C:\PROGRA~2\Android\android-sdk\system-images\android-31\default\x86_64\ramdisk.img: 1 file pushed, 0 skipped. 181.9 MB/s (4106161 bytes in 0.022s)
[-] Copy rootAVD Script into Magisk DIR
rootAVD.sh: 1 file pushed, 0 skipped. 129.9 MB/s (7847625 bytes in 0.058s)
[-] run the actually Boot/Ramdisk/Kernel Image Patch Script
[*] from Magisk by topjohnwu and modded by NewBit XDA
[!] We are in a ranchu emulator shell
[-] Api Level Arch Detect
[-] Device Platform is x64 only
[-] Device SDK API: 31
[-] First API Level: 31
[-] Switch to the location of the script file
[*] Extracting busybox and Magisk.zip ...
[-] Checking AVDs Internet connection...
[!] AVD is online
[!] Checking available Magisk Versions
wget: short read, have only 30
[?] Choose a Magisk Version to install and make it local
[!] (s)how all available Magisk Versions
[1] local stable 'cc79a96f'(24307) (ENTER)
[2] stable 24.3
[3] canary cc79a96f(24307)
[4] alpha a32c4561-alpha(24307)
3
[-] You choose Magisk alpha Version cc79a96f(24307)
[*] Deleting local Magisk 'cc79a96f'(24307)
[*] Downloading Magisk alpha cc79a96f(24307)
wget: got bad TLS record (len:2019) while expecting encrypted data
 03 03 40 18 00 00 00 00 00 00 04 82 05 ab a3 12 fb f2 f0 ec ec b0 bf 82 37 31 50 56 bd 4f 09 9c 36 d0 13 39 b5 7f e0 ec 85 f8 00 a7 e1 33 ad 07 64 8c 73 39 7d da d8 8d 41 bb 7d 0c 4b 1a 48 da d5 d0 7e b7 06 6a 79 9a 2a 9b d9 d2 55 9e ea 3b b5 24 c3 15 f1 92 bd 72 f3 aa e4 a3 76 04 5d 24 c7 b1 f6
wget: connection closed prematurely
[!] Error while downloading Magisk alpha cc79a96f(24307)
[-] patching it together
[!] Downloading Magisk alpha cc79a96f(24307) complete!
[-] Switch to the location of the script file
[*] Extracting busybox and Magisk.zip ...
[*] Downloading USB HOST Permissions Module Zip
[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH
[-] We are now in Magisk Busybox STANDALONE (D)ASH
[*] rootAVD with Magisk cc79a96f(24307) Installer
[-] Get Flags
[*] System-as-root, keep dm/avb-verity
[-] Encrypted data, keep forceencrypt
[*] RECOVERYMODE=false
[-] KEEPVERITY=true
[*] KEEPFORCEENCRYPT=true
[-] copy all x86_64 files from /data/data/com.android.shell/Magisk/lib/x86_64 to /data/data/com.android.shell/Magisk
[*] Detecting ramdisk.img compression
[!] Ramdisk.img uses lz4_legacy compression
[-] taken from shakalaca's MagiskOnEmulator/process.sh
[*] executing ramdisk splitting / extraction / repacking
[-] API level greater then 30
[*] Check if we need to repack ramdisk before patching ..
[*] After decompressing ramdisk.img, magiskboot will work
Detected format: [lz4_legacy]
[-] Test patch status and do restore
[-] Checking ramdisk status
[-] STATUS=1
[-] Magisk patched boot image detected
[-] Constructing environment - PAY ATTENTION to the AVDs Screen
[!] we are root
su: invalid uid/gid '-c'
[!] not root yet
[!] Couldn't construct environment
[!] Double Check Root Access
[!] Re-Run Script with clean ramdisk.img and try again
[!] aborting the script

Any ideas ?
Hi,

try it with the stock ramdisk:
Code:
[-] Checking ramdisk status
[-] STATUS=1
[-] Magisk patched boot image detected
[-] Constructing environment - PAY ATTENTION to the AVDs Screen
Indicates that your ramdisk is already rooted.

Also, did you check my

[GUIDE] Build / Mod AVD Kernel Android [10] [11] [12] rootAVD [Magisk] [USB passthrough] [Linux] [Windows] [Google Play Store API]

[Update 15.12.2021]
For Windows Only.

I hope this helps.
 

theovero

Member
Jul 15, 2022
7
0
Hello how are you? I hope you're well. First I would like to apologize for the confusion created yesterday in my topic. It's the first time I'm dealing with rooted and right away it was by emulator. Secondly, I would like to thank you for the tutorial and your patience.
Today I really DISCOVERED what I need.

Can you help me?

I need to pass safetynet checks to access banking apps through android emulator. However, I've tried every possible way with safetynet kdragon, prompconfs and everything else. I've watched all the tutorials available on youtube possible, but the problem is that these tutorials only show how to do this through a real cell phone and not through an emulator. Would you help me?
 

theovero

Member
Jul 15, 2022
7
0
Yes I have added Google play services ( tried with whole Google play services and with two sub options namely gms and unstable under Google play services) to Deny list. I have also used universal safety net and Magisk Hide Props.
Hello. I saw in a post of yours that you are (or were) having the same problem as me to activate safety net in the emulator through magisk. Have you already got the solution? Would you help me??
 

-Star-Lord-

New member
Jul 17, 2022
1
0
what I'm doing wrong?
c:\rootAVD-master>rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-30\google_apis_playstore\x86\ramdisk.img
[*] Set Directorys
[-] Test if ADB SHELL is working
Access is denied.
The system cannot find the file specified.
Could Not Find c:\rootAVD-master\tmpFile

c:\rootAVD-master>
 

newbit

Senior Member
Nov 16, 2008
211
79
Hello how are you? I hope you're well. First I would like to apologize for the confusion created yesterday in my topic. It's the first time I'm dealing with rooted and right away it was by emulator. Secondly, I would like to thank you for the tutorial and your patience.
Today I really DISCOVERED what I need.

Can you help me?

I need to pass safetynet checks to access banking apps through android emulator. However, I've tried every possible way with safetynet kdragon, prompconfs and everything else. I've watched all the tutorials available on youtube possible, but the problem is that these tutorials only show how to do this through a real cell phone and not through an emulator. Would you help me?
No I can't help you with that. Never heard about anyone who made it possible to pass safetynet on an AVD.

Perhaps you should set a bounty out to achieve this.
 

newbit

Senior Member
Nov 16, 2008
211
79
Nothing changed. I try many times since last night. There is any problem with the newest AVD? I'm using
Android Studio Chipmunk | 2021.2.1 Patch 2 for Windows 64-bit (929 MiB)View attachment 5680385
Not sure, chipmunk is working fine ever since. The issue from the command says there is an issue with the code. And you are using already cmd shell instead of ps. if you run adb shell, does it connect the running avd?
 

newbit

Senior Member
Nov 16, 2008
211
79
Yes, it connect normal
I am sorry, but I can't help you.
I cannot reproduce your issue. The up to date script is working fine. So I can't really
say where your issue is coming from. I assume you didn't changed anything in the
rootAVD.bat script?! I am not sure if this could be OS ending related, but you could
try to re-download the rootAVD.bat file and overwrite it.

Good luck with it
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Hi @itsLazR,
    my apologies for the late response.
    The Log from the windows git-bash looks weird, seems
    there are issues with the space in the directory path.

    I've never tried the script with windows git-bash, don't think
    this will work. But if you show me your windows cmd logs,
    I can probably help you more with that.

    Ah, I was using a different ADB folder I had previously gotten -- I think from this thread years ago. Setting it to Android Studio's folder worked. I wasn't able to install Magisk* latest via the script but the one included with the repo worked! Thank you!
    1
    Hey I am having an issue running the code -- I can push apks, just not patching ramdisk.img. Running in git bash because CMD/PS couldn't get past the ADB Shell. (even though adb shell command works)

    Android Studio Version - 2021.2.1 - Chipmunk
    Host - Windows 10
    AVD - API 31 (S) x86_64 (Google Play)

    Code:
    [email protected] MINGW64 ~/Desktop/rootAVD-master
    $ ./rootAVD.sh C:/Users/xxcmb/AppData/Local/Android/Sdk/system-images/android-31/google_apis_playstore/x86_64/ramdisk.img
    [!] 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
    [*] Cleaning up the ADB working space
    [*] Creating the ADB working space
    mkdir: 'C:/Program': No such file or directory
    mkdir: 'Files/Git/data/data/com.android.shell/Magisk': No such file or directory
    [-] Magisk installer Zip exists already
    [*] Push Magisk.zip into /data/data/com.android.shell/Magisk
    [-]
    [-] ramdisk.img Backup exists already
    [*] Push ramdisk.img into /data/data/com.android.shell/Magisk
    [-]
    [*] Push rootAVD.sh into /data/data/com.android.shell/Magisk
    [-]
    [-] run the actually Boot/Ramdisk/Kernel Image Patch Script
    [*] from Magisk by topjohnwu and modded by NewBit XDA
    sh: C:/Program: No such file or directory
    Hi @itsLazR,
    my apologies for the late response.
    The Log from the windows git-bash looks weird, seems
    there are issues with the space in the directory path.

    I've never tried the script with windows git-bash, don't think
    this will work. But if you show me your windows cmd logs,
    I can probably help you more with that.
    1
    Hey @newbit thanks for your work, amazing thing you did with this one.

    There is no way for a work around in Android Pie (28)?
    Not to my knowledge, no. If you find a way, please let me know.
    1
    @newbit is there any way to put version 23.0 in the script? I can't go back to version 23 using magisk manager.
    Sure, you can either download your desired version manually and put in the rootAVD folder. Or you can just start the script normal, and in the menu you can display all the available versions and choose the one you like. Fetching all the Magisk Versions can take some time, so be patience once you hit the button.
  • 9
    Hello Fellows,

    here is a little script, rootAVD, I wrote to root Android Studio Virtual Devices with Magisk.
    It is actually just a modified boot_patch.sh from @topjohnwu, which didn't work
    for Android 11 (R), so I tried the script from @shakalaca MagiskOnEmulator.
    Which didn't work for Android 11 (R) either, so I used his decompression routine to
    modify my rootAVD script and now it works with Android 11 (R), Android 10 (Q)
    and Android 7 (Nougat) with all the Google Play Store API Versions.
    Successfully tested with Stock Kernels on Linux, MacOS and Windows.
    Since Android 12 (S) API 31 is a 64 Bit Only System, Magisk Alpha from vvb2060 is needed.
    So, all credits go to all three of them.

    I hope this might come in handy.

    Cheers
    NewBit

    [Update 29.03.2021]
    Added Download Manager Function for bad TLS record
    Please check out the README.md for "up to date" information.

    Requesting for Help!

    Please provide the following information If you are asking for support:
    • Host System
    • Android Studio Version
    • AVD Version
    • Magisk Version
    • Terminal input & output
    Example Templates:
    Host System:
    sw_vers
    ProductName: Mac OS X
    ProductVersion: 10.15.7
    Android Studio Version: 4.1.3
    AVD Version: Google APIs Intel x86 Atom_64 System Image (revision: 2)
    Magisk Version: Stable 22.1
    Terminal input & output:
    Code:
    ./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis/x86_64/ramdisk.img
    [!] and we are NOT in an emulator shell
    [-] 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
    [-] Copy Magisk installer Zip
    [*] ./Magisk.zip: 1 file pushed, 0 skipped. 153.2 MB/s (6720493 bytes in 0.042s)
    [*] Set Directorys
    [*] create Backup File
    [-] Copy the original AVD ramdisk.img into Magisk DIR
    [*] /Users/newbit/Library/Android/sdk/system-images/android-S/google_apis/x86_64/ramdisk.img: 1 file pushed, 0 skipped. 286.9 MB/s (2507370 bytes in 0.008s)
    [-] Copy rootAVD Script into Magisk DIR
    [*] rootAVD.sh: 1 file pushed, 0 skipped. 82.8 MB/s (22575 bytes in 0.000s)
    [-] Convert Script to Unix Ending
    [-] 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.1' (ENTER)
    [2] Canary e136fb3a(22102)
    [3] Stable 22.1
    
    [1] You choose Magisk Local Version '22.1'
    [*] 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.1' 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: 30
    [-] ARCH32 x86
    [-] First API Level: 31
    [*] 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 lz4_legacy compression
    [-] taken from shakalaca's MagiskOnEmulator/process.sh
    [*] executing ramdisk splitting / extraction / repacking
    [-] API level greater then 30
    [*] Check if we need to repack ramdisk before patching ..
    [-] Multiple cpio archives detected
    [*] Unpacking ramdisk ..
    [-] Dumping from 0 to 1603441 ..
    Detected format: [lz4_legacy]
    [-] Dumping from 1603441 to 2507370 ..
    Detected format: [lz4_legacy]
    [*] Repacking ramdisk ..
    [-] Test patch status and do restore
    [-] Checking ramdisk status
    [-] STATUS=0
    [-] Stock boot image detected
    [-] Patching ramdisk
    [!] PATCHFSTAB=false
    [!] Skipping fstab.ranchu patch with /dev/block/sda
    [?] If you want fstab.ranchu patched, set PATCHFSTAB=true
    [!] patching the ramdisk with Magisk Init
    Loading cpio: [ramdisk.cpio]
    Add entry [init] (0750)
    Create directory [overlay.d] (0750)
    Create directory [overlay.d/sbin] (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
    [-] After the ramdisk.img file is patched and compressed,
    [*] pull it back in the Magisk DIR
    [*] /data/data/com.android.shell/Magisk/ramdiskpatched4AVD.img: 1 file pulled, 0 skipped. 209.3 MB/s (2918094 bytes in 0.013s)
    [-] pull Magisk.apk to Apps/
    [*] /data/data/com.android.shell/Magisk/Magisk.apk: 1 file pulled, 0 skipped. 236.2 MB/s (6720493 bytes in 0.027s)
    [-] pull Magisk.zip to Apps/
    [*] adb: error: failed to stat remote object '/data/data/com.android.shell/Magisk/Magisk.zip': No such file or directory
    [-] Clean up the ADB working space
    [*] Move and rename the patched ramdisk.img to the original AVD DIR
    [-] 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
    Code:
    ./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis/x86_64/ramdisk.img
    [!] and we are NOT in an emulator shell
    [-] 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
    [-] Copy Magisk installer Zip
    [*] ./Magisk.zip: 1 file pushed, 0 skipped. 50.7 MB/s (6720493 bytes in 0.126s)
    [*] Set Directorys
    [-] Backup exists already
    [-] Copy the original AVD ramdisk.img into Magisk DIR
    [*] /Users/newbit/Library/Android/sdk/system-images/android-S/google_apis/x86_64/ramdisk.img: 1 file pushed, 0 skipped. 339.1 MB/s (2918094 bytes in 0.008s)
    [-] Copy rootAVD Script into Magisk DIR
    [*] rootAVD.sh: 1 file pushed, 0 skipped. 104.1 MB/s (22575 bytes in 0.000s)
    [-] Convert Script to Unix Ending
    [-] 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.1' (ENTER)
    [2] Canary e136fb3a(22102)
    [3] Stable 22.1
    
    [1] You choose Magisk Local Version '22.1'
    [*] 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.1' 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: 30
    [-] ARCH32 x86
    [-] First API Level: 31
    [*] 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 lz4_legacy compression
    [-] taken from shakalaca's MagiskOnEmulator/process.sh
    [*] executing ramdisk splitting / extraction / repacking
    [-] API level greater then 30
    [*] Check if we need to repack ramdisk before patching ..
    [*] After decompressing ramdisk.img, magiskboot will work
    Detected format: [lz4_legacy]
    [-] Test patch status and do restore
    [-] Checking ramdisk status
    [-] STATUS=1
    [-] Magisk patched boot image detected
    [-] Constructing environment - PAY ATTENTION to AVDs Screen
    [!] we are root

    Also, before you ask, please answer your self the following questions:
    • Did I read AND understood the README.md ?
    • Is my question as detailed and simple as possible couched ?
    Also, please include my Username in your Salutation to make sure I will get notice of it.
    I love to help, but asking all the time, where to pick you up, just increases the time period to get
    your issues fixed.

    Download the latest Version:
    Direct: https://github.com/newbit1/rootAVD/archive/refs/heads/master.zip
    Git: git clone https://github.com/newbit1/rootAVD.git

    Use Case Examples
    on MacOS
    rootAVD_MacOS.gif


    on Windows
    rootAVD_Windows.gif


    on Linux
    rootAVD_Linux.gif
    2
    Nice, thanks for your feedback.
    I've never tried to get pass through the SafetyNet Check.
    But If you want to go further, you can try to change your devices fingerprint with MagiskHidePropsConf from @Didgeridoohan.
    So you could pass basicintegrety, and for ctsprofile you can try Universal SafetyNet Fix from @kdrag0n
    Both modules are just awesome and I have them both on my real phone for the same purpose.


    What do you mean by that? If you can't drag and drop the apk to Emulators Display to install it, there is something wrong
    with your ADB connection. I had this quite a lot, but booting the AVD up over the SDK fixed it mostly for me.


    THX , i will test it.
    I test to install Magisk and spoof with Pokemon Go

    Magisk install - Check
    Smalipatcher install - Check
    Pokemon Go install - not check (cant install)
    Joystick install - not check (cant install)

    But i will test more first
    2
    Hi @itsLazR,
    my apologies for the late response.
    The Log from the windows git-bash looks weird, seems
    there are issues with the space in the directory path.

    I've never tried the script with windows git-bash, don't think
    this will work. But if you show me your windows cmd logs,
    I can probably help you more with that.

    Ah, I was using a different ADB folder I had previously gotten -- I think from this thread years ago. Setting it to Android Studio's folder worked. I wasn't able to install Magisk* latest via the script but the one included with the repo worked! Thank you!
    1
    hi, I'am glade it works for you and grateful for your feedback.
    Do you mind telling me on which system and AVD you let the script run?

    My work System:
    OS: MacOS Catalina 10.15.6
    Android Studio 4.0.1
    AVD: Pixel 2 API 30 Android 10.0+ x86_64

    I restart AVD into safemode, then exec

    ./rootAVD.sh ~/Library/Android/sdk/system-images/android-30/google_apis_playstore/x86_64/ramdisk.img

    restart and follow the magisk to fix problem.
    1
    @newbit is there any way to put version 23.0 in the script? I can't go back to version 23 using magisk manager.
    Sure, you can either download your desired version manually and put in the rootAVD folder. Or you can just start the script normal, and in the menu you can display all the available versions and choose the one you like. Fetching all the Magisk Versions can take some time, so be patience once you hit the button.