21

I bought a Xiaomi Redmi 4x yesterday and I can't debug my apps in this device.

I already enabled the Developer Options in the device, switch on to USB Debugging, install the USB Drivers and accepted the RSA debugging fingerprint pop that appears when I plug it on USB port for the first time.

So, I select the "Xiaomi Redmi 4X (Android 6.0 - API 23)" in devices list of Visual Studio, click in Run (or deploy) and see this error:

>Detecting installed packages...
>Removing old runtime: Mono.Android.DebugRuntime...
>Target device is arm64-v8a.
>Installing the Mono shared runtime (debug - 1505313604)...
>10% ... 3520kb of 35035kb copied
>20% ... 7040kb of 35035kb copied
>30% ... 10560kb of 35035kb copied
>40% ... 14016kb of 35035kb copied
>50% ... 17536kb of 35035kb copied
>60% ... 21056kb of 35035kb copied
>70% ... 24576kb of 35035kb copied
>80% ... 28032kb of 35035kb copied
>90% ... 31552kb of 35035kb copied
>100% ... 35035kb of 35035kb copied
> Deployment failed
>Mono.AndroidTools.InstallFailedException: Unexpected install output:   pkg: /data/local/tmp/Mono.Android.DebugRuntime-debug.apk
>Failure [INSTALL_CANCELED_BY_USER]
>
>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
>   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
>   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
>   at System.Threading.Tasks.Task.Execute()
>Unexpected install output:     pkg: /data/local/tmp/Mono.Android.DebugRuntime-debug.apk
>Failure [INSTALL_CANCELED_BY_USER]
>
>Creating "obj\Debug\upload.flag" because "AlwaysCreate" was specified.
>Creating directory "obj\.cache\".
>Done building project "MyTestApp.csproj".
>Build succeeded.
>An error occured. See full exception on logs for more details.
>Unexpected install output:     pkg: /data/local/tmp/Mono.Android.DebugRuntime-debug.apk
>Failure [INSTALL_CANCELED_BY_USER]
>
>
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

This occurs with all my apps and just in this Xiaomi device. In other brand devices and emulators, the debug works normally.

Just to complement, I have this problem http://en.miui.com/thread-544718-1-1.html and even following the instructions, I can't make the "Install via USB" works.

There is any solution to debug in this device?

5
  • You should look at your device because xiaomi will ask you whether to install apk or not if you do not agree to continue to install apk , it will fail.
    – CoXier
    Sep 30, 2017 at 5:07
  • Xiaomi asks before installation... if you did not timly pressed yes or ok then it cancels by itself Sep 30, 2017 at 5:20
  • @Rafael de Andrade Do you have tired the suggestion that LiJianixn and Ashish John provided? If the problem still exist, please feel free to let us know.
    – Weiwei
    Oct 2, 2017 at 2:55
  • Hi, thanks for the help guys, but I discover that the problem was entirely related to the "Install via UBS" option, that MIUI would not let me activate. After numerous attempts and reboots of the device, it finally activated and the deploy worked at the same time. I will include this as answer, to help other people with the same problem. Oct 2, 2017 at 3:24
  • @Rafael de Andrade, Since this issue has been resolved, you could mark your solution as the answer. Thanks for your sharing.
    – Jack Zhai
    Oct 10, 2017 at 2:12

8 Answers 8

32

Just to help anyone who have the same problem: it was entirely related to the "Install via USB" option in the Developer mode, that MIUI would not let me activate. After numerous attempts and reboots of the device, it finally activated and the deploy worked at the same time.

4
  • Yes had same issue, xiomi redmi note 4, after rebooting once and trying to enable "Install via USB" thrice, on the third time it got activated Oct 6, 2017 at 8:11
  • 1
    Is there a way to activate this option without having a MIUI account? I don't like to send user data to them when I'm always logged in...
    – UNeverNo
    Feb 23, 2018 at 11:35
  • @UNeverNo have you found any solution to that? I am facing the same. Thanks
    – Gauranga
    Apr 27, 2018 at 16:38
  • @Gauranga: Unfortunately not.
    – UNeverNo
    Apr 28, 2018 at 18:45
17

In MIUI the UI does some of the optimization for some reason, but this comes out to be an error while running the app on the phone through Android Studio. We need to stop the optimization:

Go to -> Settings -> Switch on the developer option (hope you know) -> Go to developer settings -> Turn off MIUI optimization

I hope this works for you. ;)

1
  • This worked, and i only did it one time. After the first debug, i turned the option on again and continue to debug without any problem after that Apr 9, 2019 at 9:57
7

Do step by step:

  1. Turn on Install via USBin Settings>Additional Settings>Developer Options>Install Via USB(Under Debugging Section) --> Need active Mi account.

  2. Deploy app.

  3. Wait for several seconds, a notification on your Xiaomi phone will display Install via USB, then you need touch Install to allow the app to be deployed on your device. You can choose to remember this option.

0
2

Good afternoon,

I had the same problem, I have a Xiaomi mi 8 lite phone. I solved this problem by disabling MIUI optimization.

I haven't tested on many models / brands to see if this will work.

2

I had solved this by turning off the MIUI Optimization. In case you did not get the MIUI Optimization option in your developer settings, just you need to reset the default values option by tapping it multiple times.

1

Inside the developer option of Xiaomi device click on install via USB. It works without any reboot

0

Search for Install via USB and select the security option, probably your application is blocked from installing:

enter image description here

-1

I had the same problem. Additionaly activate OEM unlocking

3
  • 1
    OEM Unlocking is not required for debugging. This operation can cause security issues. Apr 25, 2022 at 15:55
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Hypenate
    Apr 30, 2022 at 13:31
  • @Hypenate This way of linking a picture does not qualify as a link-only.
    – Yunnosch
    Sep 3, 2022 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.