[Magisk] i-hunter:
]

I quote only one answer here but I found multiple with the same problem and I am resolving two issues here.

So I have 2 Xiaomi Redmi Note 4 phones, one packed with MIUI Global 10.2.1.0 and the other one packed with MIUI 10 Global 9.3.21 ROM. Both Android 6, version MRA58K (as noted in the details). However, for the same problems listed below, this might work for other devices wearing MIUI as well. On the same level though, this might not be a generic case. I don't know how it happened or why it is like this. This should be fixed in adb I guess.

I spent too much time yesterday and this might be helpful for the developer as well.

Running the patcher directly (I am using patcher 0.6.7 - current latest version), I get in both the phones the problem

!!! ERROR: Incomplete framework dump, required files missing.
You can try running the patcher while booted into recovery mode with /system mounted, it may fix this.

Now, you cannot run these phones on recovery mode with /system mounted as they don't get detected by the Smali Patcher for some reason, even though it is listed when running

$adb devices

as a device in recovery and with a shell open, you can see the mounted system.

So, back to the problem.

After not being able run directly into the phone, I struggled to copy over the framework folder to my local machine and use this in the "Browse framework" path instead of the phone itself. However, trying to copy using

adb pull "/system/framework" framework

was giving a similar error to the above:

C:\platform-tools>adb pull "/system/framework" framework
adb: error: failed to copy '/system/framework/miuisdk.jar' to 'framework\framework\miuisdk.jar': remote No such file or directory

Luckily, the solution fixes both issues. After solving this, I was able to both transfer the framework files to the PC and also direclty create the patch file without moving the files to the PC. So if you have this, and you do this, you can use method A for the creation of the patch.

SOLUTION:

To have this working, you must already have TWRP installed (bootloader unlocked and have the TWRP installed). I am not going to analyze this here.

You also need to have adb available, though if you ran across the above issue, you probably already have all of these.

Reboot into recovery and go to Mount and mount your system folder.

Connect the mobile to your PC and from the command line, run

adb shell

Since you are in recovery mode, you are now in a super user mode - as it is needed. You can be sure about this because the shell line will start with a # instead of a $.

In your command line, run the following two commands.

cd /system/framework
ls -l

This will move you into the framework folder an will list you all the files with details.

You will normally note the following lines somewhere in the middle of the list:

lrw-r--r-- 1 root root 22 Jan 23 2019 miuisdk.jar -> /data/miui/miuisdk.apk
-rw-r--r-- 1 root root 991 Jan 23 2019 miuistatssdkshared.jar
lrw-r--r-- 1 root root 25 Jan 23 2019 miuisystem.jar -> /data/miui/miuisystem.apk

What interests us (because different users might have different problems) are the entries that are like miuisdk.jar that end with

-> /some/other/file/in/another/directory

. These files mean that the files listed are not real files but instead links to other files.

In my case, listing the files under

/data/miui/

(the directory of the above linked files) showed the following:

/system/framework # ls -l /data/miui
-rw------- 1 system system 2 Jan 2 2015 cust_variant
drwxrwx--- 2 system system 4096 Jan 4 2018 whetstone

That means that none of these files actually exist. This is why adb was failing. It was trying to fetch the actual files and the link was broken so there was a failure. For users that have more than these links, they can check each link and see if the file actually exists. If it does, you don't need to do anything.

Please, note that along with my /system, /data is also mounted (otherwise false resutls might have been presented).

To fix this, simply move the links outside the framework folder with

mv miuisdk.jar miuisystem.jar ..

(will move them one level up), or entirely delete them with

rm miuisdk.jar miuisystem.jar

. Since I am not an expert in mobiles, I moved them one level up and did not delete them but haven't run in any issues up to now (which is normal since the files don't exist anyway).

Reboot your phone into normal functionality and now the patch should work fine :) :)

UPDATE

I installed the generated module both from TWRP and from Magisk and was installed succesfully. Note that I only masked the location services. And the whole thing worked fine ever after <3 Cudos to the original work of the Smali Patcher! A-M-A-Z-I-N-G work!