203

enter image description hereI am using Android Studio 2.2 Preview. I am facing the issue

Failure: Install failed invalid apk

Error: While installing apk,

I have made changes in build.gradle but could not retrack it, please suggest me solution???

Community
  • 1
  • 1
Ali Sher Kashif
  • 2,133
  • 2
  • 11
  • 13

32 Answers32

286

Android studio mac/windows/linux:

Steps in together (mac): Android Studio > Preferences > Build, Execution, Deployment > Instant Run > Uncheck : Enable Instant Run

Steps in together (windows & linux): File > Settings > Build, Execution, Deployment > Instant Run > Uncheck : Enable Instant Run

Steps in Detail :

Steps 1: Studio > Preferences (for windows & linux got to File > settings > Build, Execution, Deployment and then same as mac)

enter image description here

Steps 2: Preferences > Build, Execution, Deployment

enter image description here

Steps 3: Build, Execution, Deployment > Instant Run

enter image description here

Steps 4: Instant Run > Uncheck : Enable Instant Run

enter image description here

Abdelilah El Aissaoui
  • 4,204
  • 2
  • 27
  • 47
Amir
  • 8,821
  • 7
  • 44
  • 48
258

In Android Studio 2.3

Disable Instant Run

Settings>Build, Execution, Deployment>Instant Run

Source: comment by @Shubham A.

Edit: To Disable Instant run

In Windows:

  1. Open Find Action: Control + Shift + A.
  2. Search instant run and open instant run under settings.
  3. Uncheck Enable instant run...

In Mac: I don't have a mac, so try like

  1. Open Find Action: Command + Shift + A.
  2. Search instant run and open instant run under settings.
  3. Uncheck Enable instant run...
amitdigga
  • 6,550
  • 4
  • 26
  • 31
38

This worked for my xiaomi redmii note 4 after allowing developer options and allowing USB debugging go to settings-> developer options-> uncheck Turn on MIUI optimization Restart your device and now install the app.

Himansh
  • 389
  • 3
  • 2
21

For Android Studio on Mac :

Navigation Bar :

Android Studio > Preferences > Build, Execution, Deployment > Instant Run > Uncheck : Enable Instant Run

For Android Studio on Windows :

File > Settings > Build, Execution, Deployment > Instant Run > Uncheck : Enable Instant Run

Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41
19

 Disable Instant Run. Steps in Android Studio

Goto

 1. File -> setting(or CLRT+ALT+S)
 2. Build, Execution, Deployment -> Instant Run 
 3. Disable Instant Run

step by step (windows)

step 1 : Go to file -> settings

enter image description here

step 2 : Build, Execution, Deployment -> Instant Run

enter image description here

step 3 : disable the instant values

enter image description here

step 4 : finally disable the Instant Run

enter image description here

dev.doc
  • 569
  • 3
  • 12
  • 18
Vilas Joshi
  • 309
  • 2
  • 7
13

For Xiaomi mobile

1.Setting=>About phone=>tap 7 times on MIUI version


2.Setting=>Developer options=> Developer options (ON)

                            => USB Debugging (ON)

                            => Install via USB(ON)

Install via USB

if

enable to ON then

Disable WiFi and switch install via USB on while you are connected through mobile data and under your xiaomi account. It works!

pruthwiraj.kadam
  • 1,033
  • 10
  • 11
9

Go to

File->settings->Buil,Execution,Deployment->Instant Run->Disable it.

//now you are good to go.

Jay
  • 674
  • 11
  • 13
  • Why do you think that the Instant Run is the problem? – yakobom Apr 25 '17 at 04:30
  • @yakobom Refer this link :- https://developer.android.com/studio/run/index.html#instant-run , most of us don't have gradle configured for instatnt run so it shows the error. It is better to turn off the instant run and Instant Run requires API 21 or higher. – Jay Apr 17 '18 at 08:19
8

I encountered a similar problem, I moved the project directory, resulting in installation failure, my solution is as follows: Build->ReBuild

叶为正
  • 81
  • 1
  • 2
7

Oh my goodness, after a long time I have resolved the issue by changing the ApplicationID: "com.company.2016app" to "com.company.app" in build.grade. It resolved all my issues. Now its working great.

Ali Sher Kashif
  • 2,133
  • 2
  • 11
  • 13
7

In my case clean project and rebuild works, no need to disable instant run and restart.

H4SN
  • 1,482
  • 3
  • 24
  • 43
5

In lollipop and above versions Android introduced multiple users, When you delete an app it still exists in device. Please make sure your app is deleted from all users and then reinstall it.

You can check by going to Settings->Apps->All and check your app in the list, On selecting your app tap on more button in actionbar and select uninstall for all users.

Abdul Rehman
  • 2,313
  • 2
  • 15
  • 14
5

Below solution worked for my Xiaomi mobile phone:

Go to Settings -> Additional settings -> Developer options and check Install via USB, if toast The device is temporarily restricted shown, please turn your WI-FI off, turn on mobile data. Then try it again.

If A.S. Instance Run is still not work when you finished all steps above, perhaps you turned on MIUI optimization, please follow below step and try again:

Settings -> Additional settings -> Developer options and uncheck Turn on MIUI optimization

licaomeng
  • 919
  • 2
  • 13
  • 27
5

Different solutions for the same problem:

1. uncheck the Instant Run

Settings > Build, Execution, Deployment > Instant Run.

2. Restart Android Studio

Click on File> invalidate Caches/Restart, then click on Invalidate and Restart button from the pop up window.

3. Check Device's memory

Sometimes your device don't have enough space to install new applications, in that case android studio through this error.

4. Check manifest for Activities Declaration

Make sure that your manifest.java have declared all of the used activities properly.

Hope it would help :)

meyasir
  • 268
  • 3
  • 12
5

Android Install on Device Failure [INSTALL_CANCELED_BY_USER] **Redmi Note 3

Go to Settings -> Permissions -> Install via USB: Uncheck your App if it's listed.

Go to Settings -> Additional Settings -> Privacy: Check the Unknown Sources option.

Go to Settings -> Additional Settings -> Developer options: Check the Install via USB option.

Go to Settings -> Additional Settings -> Developer options:Enable view attribute inspection

Finally Go to Settings -> Additional Settings -> Developer options:Turn off MIUI optimization.

NOTE - Signin in to MI account is required to enable Install via USB option.

Ref: http://en.miui.com/thread-410773-1-1.html

Vivek
  • 343
  • 1
  • 5
  • 12
4

I also had the same problem, I tried the solution to disable the instant run, but you can not use the instant run, which for me is harmful, because it is an extremely useful tool.

I found another solution, which is to delete the "build" folder and re-run the project, and the error disappears, the app is executed and I can use the instant run.

Delete this folder

Jon
  • 9,156
  • 9
  • 56
  • 73
  • this effective solution, and also made me make use of the instant run and not to lose it – AAEM Apr 11 '19 at 18:10
3

If your device is a Xiaomi

  1. Enable OEM unlocking
  2. Disable Verify apps over USB

My Screenshoot

Dita Aji Pratama
  • 710
  • 1
  • 12
  • 28
2

If your device is a Xiaomi the answer is:

Go to settings > installed apps > on the top choose "ALL" > go to the bottom find "Documents" app (its in bottom because disabled) > enable it with pressing enable on the bottom screen...

edit: I was used Android Studio 2.3 at the time

Tomás Rodrigues
  • 519
  • 2
  • 17
2

Try this: Go to File> invalidate Caches/Restart then click on Invalidate and Restart button from the pop up. Now, try running your project.

Roger Amanna
  • 151
  • 1
  • 9
2

You need rebuild the project

If using Android Studio 2.3:

Build -> Rebuild Project

Even if after that your app start with a error just rebuild the project again:

Build -> Rebuild Project
Hugleo
  • 21
  • 2
2

In Device Developer option

Check Install Via USB is ON compulsory.

Pinak Gauswami
  • 789
  • 6
  • 10
2

I had same problem in my xiaomi note 4a device. I solved it by turning off MIUI optimization.

Ganesh Giri
  • 1,135
  • 11
  • 18
2

I also faced same problem. If you want install your application using USB. You have to check the (Install Via USB option in Redimi note4). Hope this will be helpful to someone. enter image description here

1

If Emulator is opened, please close it.

And Restart the android studio.It worked for me.

Give a try.

Heman hijack
  • 209
  • 3
  • 9
1

Before you run any android app on a phone for the first time, make sure that you don't forget to set the Install via USB option. Otherwise the above error will be reported.

1

I just updated minSdkVersion to 17 and sync. And then I solved that problem.

in the build.gradle(Module:app), Change like below.

defaultConfig {
    ...
    minSdkVersion 17
    ...
}
c-an
  • 3,543
  • 5
  • 35
  • 82
0

When i try create another package under the Java folder this error will happen

But When i moved this special package under the main package of my project , everything will be ok .

I'm testing on real android device .(Sumsung J2)

SAYE
  • 1,247
  • 2
  • 20
  • 47
0

I have solved this issue by:

  1. go to sdk folder/platform-tools by cmd ,type adb shell
  2. delete all the .apk files of your project from ../output-folder
  3. restart your emulator
  4. run your project.
Peter
  • 587
  • 6
  • 16
0

This error comes with Android Studio lower than 2.4 when you try to enable Java 8 features in gradle settings following the instruction. Error can be reproduced in a new project with those gradle settings.

A higher version is needed, or a preview one.

Zon
  • 18,610
  • 7
  • 91
  • 99
0

Solution for my specific case:

Maybe it has happened because you have installed your apk first by the Google Play (my apk was running OK until I found an error) and then trying to reinstall it from your Android Studio (in order to figure it out), I have a solution:

Go to your phone/tablet. Settings -> Backup & Reset -> Disable Automatic Restore

I hope it works :)

Alberto Crespo
  • 2,429
  • 5
  • 28
  • 51
0

Even after following all the suggestions, if it shows error then check your buildType in Gradle.

Make sure signingConfig signingConfigs.config

is in release scope, not in debug.

Prashant_M
  • 2,868
  • 1
  • 31
  • 24
Sloka Roy
  • 17
  • 5
0

Check </provider> that have been added recently to the manifest

Something like android.support.v4.content.FileProvider

Also check authorities of the </provider> if it's correct

Mohamed Embaby
  • 960
  • 8
  • 26
0

I was getting the same Error in MI Note 4 I solved my problem :- Enable Install via USB in Developer Option. Developer Option>>Install Via USB To enable Install Via USB Turn off WiFi And Turn On Network Data and try to Enable

Alok Panday
  • 403
  • 4
  • 10