francescotescari / XiaoMiToolV2

XiaomiTool V2 - Modding tool for xiaomi devices
https://www.xiaomitool.com
Apache License 2.0
625 stars 124 forks source link

Xiaomi procedure failed: [getServiceToken] Missing serviceToken cookie #23

Closed rodrgz closed 2 years ago

rodrgz commented 3 years ago

I followed the instructions to unlock my Xiaomi phone, but I found this procedure error in the current linux version and in the Windows version.

Screenshot from 2021-07-13 09-35-19

morfikov commented 2 years ago

Ok, I've managed to figure out what was wrong with my setup. Gradle version (4.4.1) was to old for the java version (11.0.12) that my system was using. I had to update gradle to 7.2. Also gradle wrapper needed to be updated, but it updated automatically. Then it worked, but the linux adb/fastboot tools were missing (only exe were in the github dir). I copied the whole res/ dir from XMT2_Linux_20.7.28.run to the github source. Then after running gradlew run the GUI showed and recognized my phone. I selected the unlock the bootloader option, and it looks it works:

https://i.imgur.com/TpJs8UU.png

I still have to wait 3 days, but I think it will work just fine now. :]

d3417 commented 2 years ago

Ok, I've managed to figure out what was wrong with my setup. Gradle version (4.4.1) was to old for the java version (11.0.12) that my system was using. I had to update gradle to 7.2. Also gradle wrapper needed to be updated, but it updated automatically. Then it worked, but the linux adb/fastboot tools were missing (only exe were in the github dir). I copied the whole res/ dir from XMT2_Linux_20.7.28.run to the github source. Then after running gradlew run the GUI showed and recognized my phone. I selected the unlock the bootloader option, and it looks it works:

https://i.imgur.com/TpJs8UU.png

I still have to wait 3 days, but I think it will work just fine now. :]

Perfect, my piece of code it's a fix! I'm happy for this ^_^

CavaleriOmar commented 2 years ago

@d3417 Congrats on the accomplishment... I'm still considering whether to get another XIaomi to replace my Redmi 6 that's ready to abandon me... this may weigh on my choice

pixrafal commented 2 years ago

@d3417 thanks a lot, I tested it and looks like it pass 2FA verification, but I got failed message on terminal :

[15:22:40][PSTA ][-------] Start process (826): "./res/tools/fastboot" "-s" "xxxxxxxx: uid or device id" "oem" "unlock" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.....: huge numbers, maybe it's token or private key?" [15:08:14][PROC ][][-------]] Process (826) output: FAILED (Command length to RawCommand() is too long) [15:22:40][PROC ][-------] Process (826) output: fastboot: error: Command failed [15:22:40][INFO ][-------] Process (826) ended with exit code: 1, output len: 134 [15:22:40][WARN ][-------] InstallException created: unlock_error - Failed to unlock the device, fastboot exit with status non zero or internal error

here is error message from app 螢幕快照 2021-08-25 15 22 58

I did try a lot and get same result, and run-out quota of receiving 2FA code today.

andresangelini commented 2 years ago

git clone https://github.com/francescotescari/XiaoMiToolV2

src/main/java/com/xiaomitool/v2/gui/controller/LoginController.java Line 39:

Replace that line with: private static final String LOGIN_URL = "https://account.xiaomi.com/pass/serviceLogin?sid=unlockApi&json=false&passive=true&hidden=false&_snsDefault=facebook&checkSafePhone=true&_locale=" + Locale.getDefault().getLanguage().toLowerCase(); After that do gradle build && gradle run , login with 2FA verification, try to unlock your bootloader!

I've not tried myself because i don't want to use another smartphone for 2FA Verification and to Lock & ReUnlock the Bootloader, but if works, please mention me in this thread and tell me if you're able to unlock bootloader and mod your Xiaomi Smartphone!

I'm trying to follow @d3417's steps and I'm able to start up the program but after selecting the region the window gets stuck in a "loading" loop. The console reports a warning with "miui.com is not reachable but it is reachable on port 80", not sure if it has anything to do with it, though.

A recap of the steps I took (slightly different from above since I had to use gradle wrapper:

  1. Downloaded the ZIP of the linux branch of the project so as to make sure I had all the proper tools (adb and fastboot) to run on linux from https://github.com/francescotescari/XiaoMiToolV2/tree/linux
  2. Replaced line 39 with the above suggested code in src/main/java/com/xiaomitool/v2/gui/controller/LoginController.java
  3. I had the same problem as @morfikov but I solved it by changing the suggested commands to use gradle wrapper instead:
    ./gradlew build && ./gradlew run

    I must be doing something wrong but I can't figure out what exactly. I'll keep trying and report back if I find anything else.

DARED3ViL90 commented 2 years ago

I have a Poco F1 and I'm stuck at the same problem.

Any help would be much appreciated. Thank you so much. I'm on Kubuntu 20.04 LTS, and I have ADB and Fastboot installed. I tried with versions 20.7.28 and 9.11.10. Still the same error.

morfikov commented 2 years ago

@andresangelini, I see the same messages in the log, but the GUI works without a problem.

Basically, I wasn't aware of the linux branch. You can simply:

$ git clone https://github.com/francescotescari/XiaoMiToolV2
$ git checkout linux

And edit the affected file. In this way, you don't have to do anything else to the source.

Also gradlew (gradle wrapper) is needed instead of just gradle, because the project use the gradle wrapper. I just had to update the gradle/gradle wrapper for java 11+ which is default in my linux.

morfikov commented 2 years ago

Ok guys, I've managed to unlock my phone:

Screenshot from 2021-08-27 13-31-25 Screenshot from 2021-08-27 13-31-31 Screenshot_2021-08-27-15-58-07-496_com android settings

DARED3ViL90 commented 2 years ago

Ok guys, I've managed to unlock my phone:

Screenshot from 2021-08-27 13-31-25 Screenshot from 2021-08-27 13-31-31 Screenshot_2021-08-27-15-58-07-496_com android settings

Congrats, man! well done! Would you please share the binary with us? it'd be really very much appreciated.

morfikov commented 2 years ago

i just did it via:

gradlew build && gradlew run

So I don't have any binary, I don't know how to make the .run file.

dessalines commented 2 years ago

Most importantly, where is @francescotescari ? This change should be merged and a new release made, because all verify's are going to have this issue until this fix is merged.

DARED3ViL90 commented 2 years ago

okay, so thanks to @morfikov i got the tool to compile and start. But now the tool does not detect my phone. It returns this error: 19:01:42][INFO ][3baf8fb6] Total connected device found: 0 [19:01:42][INFO ][3baf8fb6] Showing no devices visual [19:01:44][PSTA ][2527d55d] Start process (8): "./res/tools/adb" "devices" [19:01:44][PSTA ][2527d55d] Start process (9): "./res/tools/fastboot" "devices" [19:01:44][ERROR ][2527d55d] Cannot execute fastboot command "fastboot devices", reason: Cannot run program "./res/tools/fastboot": error=2, No such file or directory [19:01:46][PSTA ][2527d55d] Start process (10): "./res/tools/adb" "devices" [19:01:46][PSTA ][2527d55d] Start process (11): "./res/tools/fastboot" "devices" [19:01:46][ERROR ][2527d55d] Cannot execute fastboot command "fastboot devices", reason: Cannot run program "./res/tools/fastboot": error=2, No such file or directory [19:01:49][PSTA ][2527d55d] Start process (12): "./res/tools/adb" "devices" [19:01:49][PSTA ][2527d55d] Start process (13): "./res/tools/fastboot" "devices" [19:01:49][ERROR ][2527d55d] Cannot execute fastboot command "fastboot devices", reason: Cannot run program "./res/tools/fastboot": error=2, No such file or directory [19:01:51][PSTA ][2527d55d] Start process (14): "./res/tools/adb" "devices" [19:01:51][PSTA ][2527d55d] Start process (15): "./res/tools/fastboot" "devices" [19:01:51][ERROR ][2527d55d] Cannot execute fastboot command "fastboot devices", reason: Cannot run program "./res/tools/fastboot": error=2, No such file or directory

Obviously it's stuck in a loop.

On the other hand ADB can detect my phone normally.

Any idea what should I do?

morfikov commented 2 years ago

Switch to the linux branch:

$ git checkout linux

DARED3ViL90 commented 2 years ago

IT FINALLY WORKED! EUREKA! Thank you everyone! And special thanks to @morfikov!

andresangelini commented 2 years ago

Congratulations @morfikov! I've been reading a lot of negative experiences regarding how much time people have to wait to get their xiaomi accounts authorized. I'm glad that was not your case.

Unfortunately, I'm still struggling with XiaoMiToolV2 getting out from the "loading" screen. I removed the project folder completely, cloned the project, then switched to the linux branch and finally edited the file as you suggested but still no luck.

As I understand it, the project uses gradle wrapper and so there should be no need to install it on my system. But, would that be my mistake and the reason it is not working?

Most importantly, where is @francescotescari ? This change should be merged and a new release made, because all verify's are going to have this issue until this fix is merged.

I agree completely with you, but unfortunately, @francescotescari has already stated in the project's readme file that this project is semi-abandoned due to lack of time and suggested not too invest too much time on it, so there doesn't see to be much reason for hope. Unless , that is, that somebody else decides to fork it or something.

morfikov commented 2 years ago

@andresangelini I've written an article on how I've managed to unlock my phone. Take a look at it. It's in Polish, but all the necessary commands are included for ctrl+c and ctrl+v. :)

andresangelini commented 2 years ago

Perfect, morfikov! I'll take a look right now.

andresangelini commented 2 years ago

Good news! Thanks to @morfikov's post I figured out that perhaps I should try installing the Java Development Kit:

sudo apt install default-jdk

Alas, after firing XiaoMiToolV2 again:

./gradlew run

Now I could finally advance to the next stage (choosing whether your phone is working normally or it's bricked).

I'll report back again soon.

andresangelini commented 2 years ago

Ok. I just bumped with a new problem (possible two but I think they are related). Since this the device that I'm using for 2FA, I try to log in into my Xiaomi account through XiaoMiToolV2 first, before doing anything to it. However, when I enter my 2FA code sent via SMS, it doesn't recognized it as valid. I eventually was able to bypass this by momentarily disabling 2FA through the Xiaomi website but then, when trying to ask for the authorization token, XiaoMiToolV2 says that Xiaomi servers returned a 20031 error: "This device is not linked to an account" (even though it has been linked since I bought it years ago).

Any ideas? Thanks once again.

morfikov commented 2 years ago

When you log into your account on the website (https://account.xiaomi.com/), do you see your phone listed there?

andresangelini commented 2 years ago

When you log into your account on the website (https://account.xiaomi.com/), do you see your phone listed there?

Yes, I do see it there. Actually, I don't recall having this issue with the XMT2_Linux_20.7.28.run file, so perhaps the key lays on the link we replaced in 39 of src/main/java/com/xiaomitool/v2/gui/controller/LoginController.java. I'll try to look a little bit more into it tomorrow since I almost ran out of 2FA trials for today.

It may take some time until @francescotescari checks out and accept the @vmavromatis' pull request but I'm hoping to fix the problem I'm having anyways just in case anyone is going through the same and doesn't want to wait until a patched version come out.

sethidden commented 2 years ago

I've written an article on how I've managed to unlock my phone. Take a look at it. It's in Polish, but all the necessary commands are included for ctrl+c and ctrl+v. :)

Thanks! Following these instructions helped me unlock by bootloader. I couldn't unlock it using the official https://en.miui.com/unlock/download_en.html program (I got a "Your account is not authorized for this operation" error and didn't know what to do), but applying the patch the switching to the "linux" branch did it for me :)

S-Paul commented 2 years ago

Hello everybody! I proceed all instructions(clone git repo, switch branch, change string) and now have error:

...
[10:39:51][INFO  ][4d725031] Starting unlock procedure
#
# A fatal error has been detected by the Java Runtime Environment:
#

#  SIGSEGV (0xb) at pc=0x00007f37070b3306, pid=29590, tid=29616
#
# JRE version: OpenJDK Runtime Environment (11.0.12+7) (build 11.0.12+7-post-Debian-2)
# Java VM: OpenJDK 64-Bit Server VM (11.0.12+7-post-Debian-2, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x8d5306]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /mnt/data/android/XiaoMiToolV2/hs_err_pid29590.log
#
# If you would like to submit a bug report, please visit:
#   https://bugs.debian.org/openjdk-11
#

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 134

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4m 29s
4 actionable tasks: 2 executed, 2 up-to-date

What i missed or did wrong? Debian 11, Openjdk 11.0.12.

cynici commented 2 years ago

First and foremost, thank you all for this workaround.

This is what I did to unlock Poco F1 using Fedora 34 workstation.

  1. As at 2021-08-29, there is no more waiting period or manual form to request for unlock approval from Xiaomi. Instead follow every step described in this video https://youtu.be/pByHHTvms4k

  2. Clone and check out linux branch

    git clone https://github.com/francescotescari/XiaoMiToolV2.git && cd XiaoMiToolV2 && git checkout linux
  3. Edit one Java source file exactly as described https://github.com/francescotescari/XiaoMiToolV2/issues/23#issuecomment-904082515

  4. Install openjdk-11, sudo dnf install java-11-openjdk

  5. Install gradle by following just Step 2, https://docs.gradle.org/current/userguide/installation.html#step_2_unpack_the_distribution. I didn't bother to set up PATH, etc. described further on the page.

  6. Set up Gradle wrapper. This step will inevitably overwrite a few Gradle-related files in the repo, i.e. gradlew, etc.

    # Step above got me gradle-7.2. Adjust this if you've got a newer release.
    /opt/gradle/gradle-7.2/bin/gradle wrapper
  7. Build using the wrapper, ./gradlew build. If this fails, you have probably messed up the Java source code edit.

  8. Run application, sudo ./gradlew run

  9. After clicking on the "unlock bootloader" button in the app, please be patient. My phone showed a static "MIUI" for over 3 minutes which kinda frightened me. But it eventually booted normally into a fresh install (like factory reset) and showed the "unlocked" status under Developer Options.

vmavromatis commented 2 years ago

Thank you all for the guides. I am reaaaaaaally close to making it following @cynici 's guide, however I get exact same issue as @andresangelini :

[15:17:50][INFO  ][34b14602] Unlock request (/api/v3/ahaUnlock) response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}
[15:17:50][INFO  ][34b14602] Unlock request response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}

I returns error 20031 says the device is not bound to my account (it is). I am logged in with same account both in phone and tool ..... So I don't know what's going on..... anyway I am happy for almost making it but sad for the error. If anyone has any ideas, pls share.

cynici commented 2 years ago

Thank you all for the guides. I am reaaaaaaally close to making it following @cynici 's guide, however I get exact same issue as @andresangelini :

[15:17:50][INFO  ][34b14602] Unlock request (/api/v3/ahaUnlock) response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}
[15:17:50][INFO  ][34b14602] Unlock request response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}

I returns error 20031 says the device is not bound to my account (it is). I am logged in with same account both in phone and tool ..... So I don't know what's going on..... anyway I am happy for almost making it but sad for the error. If anyone has any ideas, pls share.

Hi @vmavromatis

Sounds to me you have missed one step before using the XiaomiToolV2. I will edit my comment to fix that. Watch this video https://youtu.be/pByHHTvms4k?t=106. Pay attention to the step right after enabling USB debugging.

morfikov commented 2 years ago

Hello everybody! I proceed all instructions(clone git repo, switch branch, change string) and now have error:

...
[10:39:51][INFO  ][4d725031] Starting unlock procedure
#
# A fatal error has been detected by the Java Runtime Environment:
#

#  SIGSEGV (0xb) at pc=0x00007f37070b3306, pid=29590, tid=29616
#
# JRE version: OpenJDK Runtime Environment (11.0.12+7) (build 11.0.12+7-post-Debian-2)
# Java VM: OpenJDK 64-Bit Server VM (11.0.12+7-post-Debian-2, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x8d5306]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /mnt/data/android/XiaoMiToolV2/hs_err_pid29590.log
#
# If you would like to submit a bug report, please visit:
#   https://bugs.debian.org/openjdk-11
#

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 134

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4m 29s
4 actionable tasks: 2 executed, 2 up-to-date

What i missed or did wrong? Debian 11, Openjdk 11.0.12.

I had the same with my current Debian installation (sid/unstable). I don't know why it happens and how to fix it. You can download the latest ubuntu lts, and boot the live system and after you do all the steps again, it should work well.

S-Paul commented 2 years ago

Hello everybody! I proceed all instructions(clone git repo, switch branch, change string) and now have error:

...
[10:39:51][INFO  ][4d725031] Starting unlock procedure
#
# A fatal error has been detected by the Java Runtime Environment:
#

#  SIGSEGV (0xb) at pc=0x00007f37070b3306, pid=29590, tid=29616
#
# JRE version: OpenJDK Runtime Environment (11.0.12+7) (build 11.0.12+7-post-Debian-2)
# Java VM: OpenJDK 64-Bit Server VM (11.0.12+7-post-Debian-2, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x8d5306]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /mnt/data/android/XiaoMiToolV2/hs_err_pid29590.log
#
# If you would like to submit a bug report, please visit:
#   https://bugs.debian.org/openjdk-11
#

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 134

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4m 29s
4 actionable tasks: 2 executed, 2 up-to-date

What i missed or did wrong? Debian 11, Openjdk 11.0.12.

I had the same with my current Debian installation (sid/unstable). I don't know why it happens and how to fix it. You can download the latest ubuntu lts, and boot the live system and after you do all the steps again, it should work well.

I test it on other pc(debian too), and have error 10000. Find many answers with possible solutions(log out, wait, log in). Wait now...

d3417 commented 2 years ago

Sorry for the late reply, i can't help peoples with Debian because i've ArchLinux, my JDK Version is java-12-j9 (default) and it works without any problem, about the problem of @pixrafal i think that is a problem of getting the Unlock Key for fastboot, i suggest to switch to Java 12 and retry, thanks @CavaleriOmar , you're welcome :-)

d3417 commented 2 years ago

In any case try to run the Tool with sudo or root user, if there are still any problem please reply with the full output and a screenshot of the error and i try to find a solution, my system is:

OS: Archman 2021-05 Mardin Kernel: x86_64 Linux 5.13.5-arch1-1 RAM: 18377MiB / 23913MiB

I run the tool with sudo ./gradlew run

S-Paul commented 2 years ago

Hello. I did something else: Logout in browser.(i think it helped) Logout in phone, log in phone. Run gradlew run, and now it looks ok - "...wait 7 days...":) Thank you!

nitsan57 commented 2 years ago

Hi, I have another issue, it complies, but when getting to login page, the app crashes with exception. Anyone encountered this error? I am using linux mint which is based on ubuntu.

morfikov commented 2 years ago

Could you post a screenshot?

nitsan57 commented 2 years ago

Could you post a screenshot?

Hi, I upgraded java version to 16 and it was fixed! Thanks.

TioCareca commented 2 years ago

First and foremost, thank you all for this workaround.

This is what I did to unlock Poco F1 using Fedora 34 workstation.

1. As at 2021-08-29, there is no more waiting period or manual form to request for unlock approval from Xiaomi. Instead follow every step described in this video https://youtu.be/pByHHTvms4k

2. Clone and check out linux branch
   ```
   git clone https://github.com/francescotescari/XiaoMiToolV2.git && cd XiaoMiToolV2 && git checkout linux
   ```

3. Edit one Java source file exactly as described [Xiaomi procedure failed: [getServiceToken] Missing serviceToken cookie #23 (comment)](https://github.com/francescotescari/XiaoMiToolV2/issues/23#issuecomment-904082515)

4. Install openjdk-11, `sudo dnf install java-11-openjdk`

5. Install gradle by following just Step 2, https://docs.gradle.org/current/userguide/installation.html#step_2_unpack_the_distribution. I didn't bother to set up PATH, etc. described further on the page.

6. Set up Gradle wrapper. This step will inevitably overwrite a few Gradle-related files in the repo, i.e. gradlew, etc.
   ```
   # Step above got me gradle-7.2. Adjust this if you've got a newer release.
   /opt/gradle/gradle-7.2/bin/gradle wrapper
   ```

7. Build using the wrapper, `./gradlew build`. If this fails, you have probably messed up the Java source code edit.

8. Run application, `sudo ./gradlew run`

9. After clicking on the "unlock bootloader" button in the app, please be patient. My phone showed a static "MIUI" for over 3 minutes which kinda frightened me. But it eventually booted normally into a fresh install (like factory reset) and showed the "unlocked" status under Developer Options.

That works flawless... Thank you.

hope dev merge the changes...

andresangelini commented 2 years ago

Hi everyone! I'm happy to report that I've finally been able to unlock my Xiaomi device successfully! In my case, as it is with so many people such as @vmavromatis , I think, is that the instructions found in Youtube tutorials and internet posts are somehow confusing and very often skip important steps, leading us to believe the problem lays in XiaoMIToolV2 when instead all that was needed was to make sure to link your phone to your Xiaomi account (or if it is not working even then, re-link it, which was what I actually had to do).

So, to sum up, these are the step I took to unlock my device from Ubuntu 20.04.3 LTS:

  1. Make sure you have created a Xiaomi account. You can do this by going to their site OR even better yet, from signing in directly from Settings > Mi account in your phone.

  2. In your phone, go to Settings > About phone and tap 7 times on "Mi version" to enter in "developer" mode, which enables "Developer options" in "Additional settings".

  3. Go the to Additional setting > Developer options and turn on "OEM unlock" as well as "USB debugging".

  4. Now, a very important step which many tutorials fail to even mention: go to "Mi Unlock status". It should say "Device is locked" and "Phone is safe" if you have never done this before. Tap "Add account and device" and follow the instructions (it will tell you to turn off your wifi connection and turn on your mobile data connection). But here is the catch, even if you have created an account with this phone years ago, it may give you an error (don't remember exactly what it was). This is what I believe caused the 20031 error, @vmavromatis , because it is exactly what I was experiencing until I found somewhere in the Xiaomi forums that you only need to log out from your phone and log in back again. The problem was that by doing that you are basically creating a new account and I was afraid that could make you wait a long time to get the account authorized. Fortunately I tried it and didn't have to wait at all. And that was all the prerequisites.

  5. Before downloading the XiaoMiToolV2 github project, we need to make sure to install one of its key dependencies; the Java Development Kit (JDK), otherwise the app may open but get stuck in a loading loop screen, which is what happened to me:

    sudo apt install default-jdk

    5a. (?) You may also need to install adb and fastboot on your system but I'm not sure about this since the project already has them bundled with it. I already had them installed. Does anybody know? Thanks.

    sudo apt install adb fastboot
  6. Now clone the github project:

    git clone https://github.com/francescotescari/XiaoMiToolV2.git
  7. Change to the just downloaded project directory:

    cd XiaoMiToolV2/
  8. Switch to the linux branch:

    git checkout linux
  9. Build the project and run it with gradle wrapper. Gradle is an automation tool for developers and gradle wrapper is one of its functions which lets them attach a particular version of it to the project so that all the people working in the project can use the exact same version without having to install it on their system. You shouldn't worry too much about it. All that you need to know is that you shouldn't need to update it unless your JDK is too new for the gradle version that comes with the project, in which case you do need to install gradle so that you can then point gradle wrapper to it, as @cynici explained in Step 4 of his guide.

    ./gradlew build && ./gradle run

    And luckily that should be it for you too. I had no need to wait for the authorization by the way, but I don't know if that was just because I bought this phone years ago or they eliminated the waiting period.

Anyway, the key point to take away of all this mess is that before even trying to use XiaoMiToolV2 to get our Xiaomi account authorized and unlock our phone, we first need to link the phone to our account and turn on OEM unlock as well as USB unlock, for which we first have to enable the Developer mode. And if you get an error trying to link the phone to the account, just sign in and sign out of the Mi account from your phone.

If you don't takes those prerequisite steps you will never be able to unlock the phone and waste days thinking that there is something wrong with XiaoMiToolV2. Seriously, I can't stress this enough.

Thanks to everyone for their invaluable input! I think @cynici's guide above is going in the right direction.

Other issues:

Issue 1: In Step 9, when you try to run:

./gradlew build && ./gradle run

You get the following error (reported by @clobbe):

> Task :compileJava FAILED
Caching disabled for task ':compileJava' because:
  Build cache is disabled

Task ':compileJava' is not up-to-date because:
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-fxml/11.0.2/1b8a331d5f393b48de0aef59b3c967a312967290/javafx-fxml-11.0.2-linux.jar has been removed.
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-web/11.0.2/49ca03e2fd58cbb0ad94f6a6bd11e0c043e541a7/javafx-web-11.0.2-linux.jar has been removed.
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-controls/11.0.2/5f6929050a744aab39ebfc1e8e5dd03bcd2ad47b/javafx-controls-11.0.2-linux.jar has been removed.
Full recompilation is required because unable to get source-classes mapping relationship from last compilation. Analysis took 0.0 secs.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.139 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.

Fix: Remove openjfx from Ubuntu 20.04, as @paolodepa suggested (thanks Paolo!).

pixrafal commented 2 years ago

about the problem of @pixrafal i think that is a problem of getting the Unlock Key for fastboot, i suggest to switch to Java 12 and retry, thanks @CavaleriOmar , you're welcome :-)

@d3417 thanks, now i am using BellSoft Liberica JDK 11.0.12+7 without any issue for any java project, and OK, I will try to upgrade to latest jdk16 then try again.

vmavromatis commented 2 years ago

thank you so much for the support @andresangelini however even though I have tried everything that you mentioned (and more) I am still stuck with this problem https://xiaomi.eu/community/threads/mi-unlock-status-unlocked-but-actually-locked.43787/..... To make things worse Mi Flash tool wont let me do anything because it says that the bootloader is locked.... My only guess is that at some point years ago I unlocked it with another Mi Account and now it got confused because I use another one for both the phone and the tool. Anyway, I will not derail the threaad any more, seems like the culprit of the main issue is found, I am just stuck in xiaomi hell right now.

andresangelini commented 2 years ago

@vmavromatis, have you ever unlocked this device before and locked it back for some reason? As far as I know, you can lock a Xiaomi phone back provided you have installed the original MIUI OS it came with. Otherwise your phone should already be unlocked and there should be no reason to use XiaoMiToolV2 to begin with.

If the bootloader is locked, but you can't get your account authorized, how about you log out from your phone, make sure it's not linked to any account at all by logging in through the website, and then create a new account from your phone?

There has to be a solution, nobody deserves to be stuck in Xiaomi hell. :(

Clobbe commented 2 years ago

@andresangelini - thanks for summarizing well above :+1:

I tried all of the steps but am getting stuck on step 9. When I run: ./gradlew build && ./gradle run

Should add that I'm too on Ubuntu 20.04 LTS.

Everything seems to go well during the build phase. However when ./gradle run is executed I get the following error msg:

> Task :compileJava FAILED
Caching disabled for task ':compileJava' because:
  Build cache is disabled

Task ':compileJava' is not up-to-date because:
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-fxml/11.0.2/1b8a331d5f393b48de0aef59b3c967a312967290/javafx-fxml-11.0.2-linux.jar has been removed.
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-web/11.0.2/49ca03e2fd58cbb0ad94f6a6bd11e0c043e541a7/javafx-web-11.0.2-linux.jar has been removed.
  Input property 'classpath' file /root/.gradle/caches/modules-2/files-2.1/org.openjfx/javafx-controls/11.0.2/5f6929050a744aab39ebfc1e8e5dd03bcd2ad47b/javafx-controls-11.0.2-linux.jar has been removed.
Full recompilation is required because unable to get source-classes mapping relationship from last compilation. Analysis took 0.0 secs.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.139 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.

I get that it seems to be some files missing, but since I'm no Java-expert I can't really figure out how to fix this...

Got any input/feedback on what's going wrong here? Thank you for any help! Like many others of you, I'm tired of being stuck behind the Xiaomi-walls =)

paolodepa commented 2 years ago

Consider also removing openjfx packages if installed: gradle downloads and runs its own version and finding different libraries on the system can create confusion...

Clobbe commented 2 years ago

Consider also removing openjfx packages if installed: gradle downloads and runs its own version and finding different libraries on the system can create confusion...

Thanks @paolodepa that seems to work. Now the app is starting properly and I was able to successfully unlock the bootloader. Cheers!

ZlllC commented 2 years ago

Any way out for MacOS users there? it seems the workaround to bypass 2FA only works on Linux? Any help would be much appreciated.

andresangelini commented 2 years ago

@Clobbe, sorry for the late replay, and @paolodepa, thanks a lot forma solving his problem. I have updated the guide above with a new "Other issues" section with the issue @Clobbe was having and its fix. The idea is to add there new issues and their fixes as they appear.

andresangelini commented 2 years ago

@ZlllC, have you tried to follow the suggestions people have given in this issue but using the Mac branch of the project? I don't use a Mac so I'm not sure what are the commands you need to use, let alone what come installed in MacOS, but maybe we can help you somehow.

saleksandarz commented 2 years ago

@Clobbe try sudo ./gradlew build && sudo ./gradlew run

saleksandarz commented 2 years ago

I did all from above steps but now I'm getting this Screenshot_20210905_124333 Screenshot_20210905_131214

adb and fastboot are working. arch linux and pocophone f1 global (miui 12.0.3)

callmenoodles commented 2 years ago

Thank you all for the guides. I am reaaaaaaally close to making it following @cynici 's guide, however I get exact same issue as @andresangelini :

[15:17:50][INFO  ][34b14602] Unlock request (/api/v3/ahaUnlock) response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}
[15:17:50][INFO  ][34b14602] Unlock request response: {"code":20031,"description":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descCN":"请在MIUI上绑定账号后解锁:开发者模式下打开设置,搜索设备解锁状态,然后进行绑定","descEN":"Please add your account in MIUI's Settings > Developer options > Mi Unlock status.","uid":"6492342286"}

I returns error 20031 says the device is not bound to my account (it is). I am logged in with same account both in phone and tool ..... So I don't know what's going on..... anyway I am happy for almost making it but sad for the error. If anyone has any ideas, pls share.

On your phone:

  1. Go to Developer Options > Mi Unlock Status
  2. Add your account. If it fails to add, sign out in Accounts and sign in again, then repeat this step
  3. Try running XiaoMiTool v2 again.
nocturn9x commented 2 years ago

Thanks a lot guys, I was able to get this working. Now I just need to wait the canonical 168 hours and I'll be finally able to unlock my phone!

rodrgz commented 2 years ago

I did all from above steps but now I'm getting this Screenshot_20210905_124333 Screenshot_20210905_131214

adb and fastboot are working. arch linux and pocophone f1 global (miui 12.0.3)

I'm reproducing it