Android - Enable "Install via USB" without creating MI Account
What I didn't want was to continue having an MI account connected to my device. So I just created a temporary account, enabled the "Install via USB" option and then logged out from the MI account. So, now I hope the option stays enabled :)
For those who have already inserted their sim card into the Xiaomi phone, the above answers all would work.
But, if you are using Xiaomi Redmi 5 only for development purposes, you will need to do as per below:
You will need to sign up/sign in for a Mi account before you continue.
1) Extract sim card from your non-Redmi phone. (It should be nano sim. Contact your telecom provider to get one if you have a micro or normal sim).
2) Insert sim card into Redmi phone.
3) Go to Settings -> Additional Settings -> Developer options.
4) Under Debugging, click on 'Install via USB' option.
The phone will enable this.
Remove the sim card.
That's it!! You should now be able to install your apps via USB from Android studio.
Please remember not to disable this option, otherwise, you may need to re-insert your sim card.
PLEASE NOTE: The above steps are guaranteed to work in Xiaomi Redmi 5 phone. Please improve this answer if the steps are different for other models of Xiaomi.
None of the other solutions floating around the internet worked for me (Chinese VPN, Disabling MIUI optimization...). I also could not temporarily sign into a Mi account, since I'd uninstalled as many MIUI system apps as I could and thus sign-in wasn't working anymore (and I just didn't want to sign in to begin with).
YMMV - it worked for me when I did it in early 2019, but it may not work any more if they changed something. I changed to custom ROM and can't test it anymore.
If you want to change it back, just re-run the commands with a
0 at the end and remove what you added to the text files.
This requires root, shell access with
su, and a way to edit text files as root. I used Termux and and an android root file manager that can edit text files.
First, run the following command (
su first, to switch to root):
setprop persist.security.adbinstall 1
If you also want to enable "USB debugging (Security settings)", for granting permissions, simulating UI input, etc. via ADB, run the following command too:
setprop persist.security.adbinput 1
Next, we need to edit the file
so that MIUI actually lets us do these things:
Add the following line to the XML file (with all the other ones, before the closing
</map> tag, or change it to
true if the line is already there):
<boolean name="security_adb_install_enable" value="true" />
Reboot your device. MIUI annoyingness circumvented :-)