If you’re like me who is using a Xiaomi phone and at the same time developing a React Native App, you will at some point want to test your app on a real device. But since the device is a Xiaomi phone, you might run into a bit of a trouble.
Problem #1: Unable to install APK ‘app-debug.apk’ on device.
Basically, uploading the debug APK to the phone failed. There are some suggestions that you should upgrade or downgrade Gradle to a certain version but before you do that, do this:
Go to Settings > Additional settings > Developer options, scroll to the very bottom and turn off “Turn on MIUI optimization”. Wait for your phone to reboot and try again.
In my case, I’m able to get it running after turning off MIUI optimization in development mode. If this doesn’t work, you might want to consider looking into other options.
Problem #2: In-app developer menu not showing.
So far so good… until you want to access the developer menu. You might be shaking your phone violently hoping the menu will pop up. No luck! At one point I thought my phone’s accelerometer is not working but it turns out, yet again MIUI is the culprit.
The developer menu is blocked by MIUI by default. To fix this:
Go to Settings > Installed apps > [Your App Name] > Permission manager, and enable “Display pop-up window”.
Shake again. The developer menu should pop up as expected with just a little shaking. If not, most likely there is a hardware problem. You can test your accelerometer using the Compass app that comes with MIUI.
MIUI might be friendly and easy to use for normal users but not so friendly to developers. Not saying MIUI is bad, just that it’s not that straightforward for developers. IMHO, MIUI is one of the best Android ROMs out there, especially if you’re coming from iOS world.
Note that the settings might be a little different depending on the version of MIUI. My Xiaomi phone is a Mi 4i running Android Lollipop (5.0.2) and MIUI 8.2 (Global).