177

Yesterday my app was running perfect from Android Studio but today when I started working on my app and running it i am getting error message continuously

Installation failed with message Failed to establish session.

Screen :

enter image description here

On click OK getting error message

Session 'app':Error Installing APKs

And App is not exist(already Uninstalled) in device. Please suggest me what to do ?

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65

33 Answers33

355

Again in this issue also I found Instant Run buggy. When I disable the Instant run and run the app again App starts successfully installing in the Device without showing any error Window. I hope google will sort out these Issues with Instant run soon.

Steps to disable Instant Run from Android Studio:

File > Settings > Build,Execution,Deployment > Instant Run > Un-check (Enable Instant Run to hot swap code)

Zoe
  • 27,060
  • 21
  • 118
  • 148
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • 10
    It is also work on MIUI ROM without disable MIUI Optimization, When disable MIUI Optimization then few permission auto grant to application like Windowmanager permission – prakash ubhadiya Jun 20 '17 at 05:35
  • 3
    This fixed the same issue I'm having, but with a Samsung phone! – Yuki Kutsuya Apr 14 '18 at 12:43
  • 1
    more than a year later this still happens. – SilentStorm May 25 '18 at 08:14
  • Funny (not really). My worthless crap Android Studio (v3.1.2) wouldn't run with Instant Run off. – theAnonymous Jun 03 '18 at 17:06
  • 11
    For Mac, Android Studio > Preferences > Build, Execution, Deployment > Instant Run > Un-check (Enable Instant Run to hot swap code) – Vinoth Anandan Jul 06 '18 at 11:56
  • For Mac, it may be related to lack of space in the device. After disabling instant run I noticed the following message in the Debug tab: Error: android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space The Mac Android transfer application used to transfer files from the device wouldn't be able to connect either. – juanlugm Aug 18 '18 at 13:06
  • 1
    Is disabling Instant run a real solution though? It is very useful. – M. Azyoksul May 20 '19 at 00:57
  • 1
    Another year on, and its still happening. – Nick Wright Jul 05 '19 at 15:42
  • 5
    Android Studio 3.5 (upgraded from 3.3) still has the bug, but not the control. Below File > Settings > Build,Execution,Deployment there are these choices: Gradle, Debugger, Remote Jar Repositories, Compiler, Coverage, Deployment, Espresso Test Recorder, Required Plugins. No option to control Instant Run! – Quigi Sep 02 '19 at 13:38
111

If you use MIUI ROM

Go to the developer option and in that disable MIUI optimization.You will be asked to reboot your phone. Reboot it and then run the app.

Roman Nazarevych
  • 7,513
  • 4
  • 62
  • 67
Vivian Dbritto
  • 1,121
  • 1
  • 6
  • 7
51

Your APK file is missing . So , Clean Project >> Build APK >> Run the project .

roy
  • 6,685
  • 3
  • 26
  • 39
31

For those who uses Xiaomi phones, follow these steps:

  1. Settings-> Additional Settings-> Developer options

  2. Turn off MIUI Optimization and reboot your phone

  3. Last Disable verify app over USB

Your device will respond properly.

Also enable install via USB

Moussa
  • 4,066
  • 7
  • 32
  • 49
user7939485
  • 416
  • 6
  • 17
20

I had the same issue in Android studio 2.3 when I tried to test the app using Xiaomi's Mi5 and Mi4 phones. Disabling instant run didn't help me. So here is what I did.

Turn Off MIUI optimization in the Developer Options in the phone.

enter image description here
enter image description here

Then the device will be rebooted and then you'll be able to test the app over the phone.

Using this method you can still use instant run option in android studio. So this will fix your problem at least temporary. Hope that we'll be able to use MIUI optimization in the near future updates :)

thilina Kj
  • 1,300
  • 13
  • 25
19

In my case, it was because my emulator ran out of disk space.

mliu
  • 1,708
  • 15
  • 26
11

In my case, it was very a silly and funny mistake. I, accidentally without actually knowing, checked "Android Debug Bridge, Use libUsb backend". Actually it should stay unchecked..

In Mac Pro, Go Preferences - > Build, Execution,Deployment -> Debugger.enter image description here

Farruh Habibullaev
  • 2,342
  • 1
  • 26
  • 33
10

**** For MAC OSX/Windows ****

Goto *

Android Studio - Preferences (In OSX)

Android Studio - File -> Settings (In Windows)

  • in the menu bar then select

Build,Execution,Deployment - Instant run

  • then uncheck it and rebuild it will works
Community
  • 1
  • 1
Muhammed Fasil
  • 7,909
  • 2
  • 19
  • 28
9

Finally I've SOLVED it!

Below a temporary solution. Issue was reported to Google.

First of all I found in Run log that Android Studion 2.3 tries to install app-debug.apk from many slices, like this:

$ adb install-multiple -r E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_1.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\dep\dependencies.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_0.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_2.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_9.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_4.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_3.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_5.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_8.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_7.apk E:\Android_Projects\ActivityLifecycle\app\build\intermediates\split-apk\debug\slices\slice_6.apk E:\Android_Projects\ActivityLifecycle\app\build\outputs\apk\app-debug.apk

Then I tried to install only app-debug.apk from command line by:

adb install -d E:\Android_Projects\ActivityLifecycle\app\build\outputs\apk\app-debug.apk

App was installed successfully but was failed to run on my phone.

And finally:

  1. I recompiled app-debug.apk from command line as:

gradlew.bat assembleDebug

  1. Repeat installation of app-debug.apk from command line and became happy:

adb install -rd E:\Android_Projects\ActivityLifecycle\app\build\outputs\apk\app-debug.apk

This is definitely some gradle problem in AndroidStudio 2.3.

Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
BarbosSergos
  • 314
  • 1
  • 8
  • +1. My multidex apk generated from Android Studio 2.3.3 crashed on launch when the apk was installed via adb command line. Re-assembling the apk from command line Gradle solved the issue! – Yuntao Jul 26 '17 at 01:14
9

Go to Build --> Clean Project --> Run

Thats all it takes.

7

I had the same issue in MIUI. Enabling OEM unlocking worked for me without disabling MIUI optimization.

Below is a screenshot of my Redmi 3s prime developer options setting:

screenshot of my Redmi 3s prime developer options setting

Ayush Chaurasia
  • 345
  • 4
  • 9
6

In my own case, it was because my phone was out of space. For people that are facing this problem right now, if Clean Project + Build APKs does not work, check the available space on your phone or emulator.

I hope this helps.. Merry coding!

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
5

I found the solution go to

settings>build,execute,deployment>instant run>Enable instant run to hot swap code /resource change on deploy(unchecked this option)

This will work on 3.4 android studio too. thanks

Rajneesh Shukla
  • 1,048
  • 13
  • 21
  • Once this is done, make sure to check that you've enabled 'install via USB' option in developer options. Did the work for me – Ishwar Rimal Jun 22 '19 at 05:45
4

Change your applicationId in the android/app/build.gradle file.

For example:

// Change this
applicationId "com.example.myAndroidApp"
//
// to this
applicationId "com.example.somethingElse"

Then Sync your gradle then you can able to install your app, if the previous applicationId is your production id the again change it the previous one now the device will allow to install the app.

Hope this may help you....

Karl Taylor
  • 4,839
  • 3
  • 34
  • 62
Jagan
  • 590
  • 1
  • 8
  • 21
  • 1
    I've tried your method and it works! I have the original app installed in my phone which is deployed by an old computer, then I move to a new computer and copy the source code to it and try to deploy it again, but failed. Maybe it is due to different version of android studio, or gradle, etc. I've been doing all kinds of funny stuffs in order to make the project works but failed. Android Studio told me to uninstall the app on the phone before deploying, I pressed OK but it said failed to install. Then I tried your method and it works! – im_chc Nov 10 '17 at 09:00
  • I think it is somehow due to the original not really being uninstalled, I still can't figure out why, but at least I am back on track now – im_chc Nov 10 '17 at 09:04
  • Helped. Thank you! – DmitryKanunnikoff Dec 13 '18 at 11:58
  • After returning to the original app id the problem is here again. I've switched off Instant Run, and it works. – DmitryKanunnikoff Dec 13 '18 at 12:03
  • I'm using Android Studio 3.4 Canary 8. This didn't help my case – Jemsheer K D Dec 14 '18 at 09:15
4

Try disabling the Instant run in Settings.

Victor C
  • 49
  • 2
  • I am getting the same issue and I disabled instant run but then I get this error message. Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzru; – nosh Mar 28 '17 at 19:58
4

Easily can be solved this problem.

Ex:- in Huawei GR3 mobile,

Goto Setting in your mobile -> Storage -> Storage Cleaner

BIS Tech
  • 17,000
  • 12
  • 99
  • 148
3

This is caused by "instant run" feature, you can disable it by:

Open the Settings or Preferences dialog. Navigate to Build, Execution, Deployment > Instant Run.

Uncheck the box next to Enable Instant Run and u are ready to go.

Vivek
  • 189
  • 1
  • 7
3

At me such error arose after renaming of a folder with the project.

Disabling Instance Run helped, but what if you do not need to disable it?

I deleted all the tags mentioning the old folder name from the file myproject\app\build\intermediates\restart-dex\debug\build-info.xml

The error has disappeared.

Petr Varyagin
  • 287
  • 3
  • 6
3

Just do the following step...

Build>Clean Project

after that Run project again, this worked for me

AtifSayings
  • 756
  • 14
  • 23
3

I also had the problem after globally changing the project name, applicationid and the folders containing the java files.

Disabling Instant run helped, but was not a good option, so this helped:

  • close Android Studio
  • deleted those files and folders: rm -Rf .gradle .tags local.properties .idea/workspace.xml .idea/caches/* .idea/libraries app/build
  • start Android Studio and let it resync everything
  • press run
rubo77
  • 19,527
  • 31
  • 134
  • 226
2

Faced same issues on MIUI phone resolved by making MIUI account and enable install by USB.

Gautam Dev
  • 399
  • 2
  • 4
2

just close your emulator and run again the problem will be solved happy coding

haribabu
  • 31
  • 2
1

Sometime app doesn't show on home screen,So Check your apps by going to setting - > apps -> and then uninstall from app setting might this work.

Nikhil Sharma
  • 593
  • 7
  • 23
1

Here's my solution (there's no need to deactivate instant run) Do all these steps in the stated order:

1- Gradle Build (root level)

gradle

2 - Gradle build + clean (app level)

gradle app

3 - Choose app on the top bar (left of Run 'app')

4 - Clean Project:

Navigate to Build > Clean Project

And it should work now! You shouldn't disable instant run if you follow these steps

Ginggas
  • 268
  • 3
  • 11
  • Build > Clean Project. Sometimes this is enough but if you do all the other steps it will work for sure – Ginggas Oct 03 '17 at 08:13
  • I'm using Android Studio 3.4 Canary 8. The error doesn't go away if i do the same as you mentioned above. It still persists. If you have any suggestions as to what may be the issue please revert. – Jemsheer K D Dec 14 '18 at 09:06
1

In my case Instant Run hided the real cause of the problem which was INSUFFICIENT_SPACE due to small data partition and I also got "failed to establish session" error. After disabling Instant Run, the real problem was revealed and after fixing it and enabling Instant Run it worked.

Andreas Oikonomou
  • 3,257
  • 2
  • 13
  • 13
1

Allow or enable "Installation from USB" in the developer options.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
1

One problem in MAC(or may be other operating systems) can also be solved with this You need disable "Use libusb backend" in preferences--> debugger

enter image description here

Please tell others if this was useful for you. Thanks to the following user and their answer: https://stackoverflow.com/a/58095554/3726185

Vivek
  • 492
  • 6
  • 15
0

Go to USB Debugging and disable MIUI Inspection and allow the phone to reboot. Things should be fine from here

0

For me I had to close the emulator and then select cold boot when re-opening it.

odiggity
  • 1,496
  • 16
  • 29
0

Before trying anything else in this post, I would do Build >> Clean Project. It solved my problem and it is the simplest solution. Sometimes, the cleaning doesnt get some links, so I also recommend you to restart your devices, either virtual or physical.

If it doesnt work out, try turning of Instant Run by File > Settings > Build,Execution,Deployment > Instant Run > Un-check

Only after trying this two simple solutions, I would try the others.

Leo Paim
  • 500
  • 7
  • 9
0

I was using the in-built emulator and kept encountering this problem.

To fix it:

  • Go to: Run > Edit Configurations
  • Click your device in the dropdown near "Preferred Android Virtual Device" and press Shift + Enter
  • Close the config screen, and focus the new window with the AVDs.
  • On the emulator you use choose the menu option on the right, and choose "stop" and "wipe data".
  • For good measure: Build > Clean Project

Some of this might be unnecessary but I can't replicate the problem deliberately in order to trial a minimum amount of steps

braks
  • 1,505
  • 15
  • 23
0

For those, who still having troubles with APK installing, just check your phone storage. In my case app failed to install always because I had not enough space to install the APK.

Ololoking
  • 1,577
  • 4
  • 22
  • 37
0

·clean project——that's what I consider first, but not work

·disable instant run——no this option in latest version

·turn off MIUI optimization——I don't use MIUI emulator

·Build apk, gradle....——no no no

You know what? When I uninstall the app in my emulator, and run the code again, it works as immediately!

vainquit
  • 491
  • 6
  • 13