Android app installation: Unknown failure (Failure

2019-02-03 02:17发布

问题:

Application works fine on emulator, but I can't launch application on my device (Xiaomi Mi4). At first i seed dialog with such text:

Installation failed with message Failed to establish session.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.

WARNING: Uninstalling will remove the application data!

Do you want to uninstall the existing application?

But after I agree - i see in log this message:

Launching app
$ adb install-multiple -r <....>
$ adb shell pm uninstall com.example.app.debug
Unknown failure (Failure - not installed for 0)
Error while Installing APKs

I've rebooted device several times and plugged/unplugged it to computer, but nothing helped.

回答1:

For Redmi and Mi devices turn off MIUI Optimization and reboot your phone.

Settings > Additional Settings > Developer Options > MIUI Optimization



回答2:

Problem is in Instant Run.

As Chirag Shah said - on Xiaomi devices you can disable MIU optimization - it worked for me too when I tried.

Another solution is to disable Instant Run in android studio settings. I've remembered - I had this problem some time ago on windows, but now it occured on linux(ubuntu). I've wrote bug report to google, but problem is still here (first time it was Android studio 2.2.3 and now it is 2.3).

For convenience: To disable Instant Run go to

File->Settings->Build, Execution, Deployment->Instant Run 



回答3:

Only Turning on "Install via USB" in Developer options did the work for me. Otherwise you may need to turn off MIUI Optimization and reboot again, but try the USB option first.



回答4:

I solved my problem by following the steps bellow

  1. Turn off Developer options.
  2. Turn on Developer options again.
  3. Turn on USB debugging
  4. Turn on Install via USB

After following the steps I run from android studio and it was installed my app successfully.



标签: android adb