94

I have updated Android studio to 3.5, ever since I am running into an APK installation problem. This is the only log it shows:

Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
Installation failed due to: 'null'
Retry

This happens when trying to install APK on a real device. If I uninstall the app from the device and then rerun the build, it installs only one time and then it keeps throwing this error on the next installation. It runs fine on an emulator but I can not use an emulator for everything.

What I have tried:

  • Deleted Android Studio configuration file.
  • Deleted Gradle files from the project.
  • Invalidated and reset caches.
  • Cleaned/rebuilt the project.
  • Looked for similar problems Stackoverflow(nothing matches my problem)
  • Clean installed(Removed all files including SDKs) Android Studio 3.5

Update

I installed Linux Mint on my machine and tested the AS 3.5 there, for some reason everything is working fine even for Android 7 and below devices.

Previous OS: Windows 10 1903

Current OS: Linux Mint 19.2

I reckon this problem may be originating from Windows machines.

Taseer
  • 3,432
  • 3
  • 16
  • 35
  • I have similar problem - but for me it's `INSTALL_PARSE_FAILED_NOT_APK` while running Espresso tests – adek111 Aug 21 '19 at 19:46
  • I'm also getting `INSTALL_PARSE_FAILED_NOT_APK` – Job Evers Aug 22 '19 at 00:58
  • I'm also getting the same issue. – Santhosh Aug 22 '19 at 07:11
  • 16
    wow Google, how can you make this a **STABLE** release?! – 0101100101 Aug 23 '19 at 03:16
  • Did you check if the Instant Run is enabled in your Android Studio? – Reaz Murshed Aug 23 '19 at 06:11
  • @ReazMurshed there is no instant run in android studio 3.5 – Manohar Aug 23 '19 at 06:30
  • But I think I saw a similar thing like instant run when I updated my Android Studio. Let me check again. – Reaz Murshed Aug 23 '19 at 06:38
  • @ManoharReddy I think the apply changes is the same thing as Instant Run. – Reaz Murshed Aug 23 '19 at 07:07
  • @ReazMurshed Actually it's completely different from instant run , its a complete rewite from scratch – Manohar Aug 23 '19 at 07:09
  • I see. Thanks for the information. Will dig for a better understanding once I have some time. – Reaz Murshed Aug 23 '19 at 07:11
  • It's because that your _Instant Run_ will not be enabled. – Piyush Aug 23 '19 at 12:52
  • In android studio 3.5 instant run is removed so how to handle error – Suyog Dorlikar Aug 23 '19 at 13:12
  • Oh I see. I haven't updated yet. But i got same error yesterday in 3.4 so above my comment worked! – Piyush Aug 23 '19 at 13:14
  • Looks like this feature is broken as well as instant run. I have to clean build every time (which is on each run) to successfully install APK on the device. – Skyyy Aug 25 '19 at 19:35
  • See my answer below. I found the solution here: https://developer.android.com/studio/run#apply-changes-run-fallback. Tested on a device running Android 9. I haven't tested it on other version. – Muhammad Baja Aksha Aug 26 '19 at 13:57
  • Finally, I got the solution in the code edit run configuration changing in Installation option DEPLOY--> from select 4th option -->(Nothing) option --> Apply And the app works properly in android studio 3.5. In mobile and emulator also. This work properly in android version 9 also This is a permanent solution. – Suyog Dorlikar Aug 28 '19 at 13:06
  • Apart from all the answers shared here, this error can also occur if your device support a different compile version than what is mentioned in the build.grade file. This can be tested by running the app on AVD with an emulator matching the API version mentioned in the file. If it runs fine, then to run it on your device you need to lower the API version to match with the one that is supported by the device. – skdhfgeq2134 Dec 29 '22 at 09:33

36 Answers36

108

Open Run/Debug Configuration dialog (Windows: Run > Edit Configurations)

edit You app > General > Installation Options > Install Flags .

add install flags -r -t.

This flags means adb install -r -t apkpath

screen pic

Saeed
  • 3,294
  • 5
  • 35
  • 52
胡晟昊
  • 1,196
  • 1
  • 7
  • 6
24

You need disable "Use libusb backend" in preferences--> debugger enter image description here

Houssin Boulla
  • 2,687
  • 1
  • 16
  • 22
12

This issue in Android Studio happens for devices lower then API 26 (Android 8). This is caused by replacement of InstantRun, known now as ApplyChanges.

Seems to be there are only two ways before they fix it in the next update.

  1. Run on API>=26.
  2. After every change in code edit run configuration changing deploy from APK to App bundle and vise-versa. If I correctly understand, this will correctly rebuild app and workaround bug.

Of course, there is an option to manually delete app from device before running app from AndroidStudio.

mohax
  • 4,435
  • 2
  • 38
  • 85
  • 1
    I have an Android 9.0 device and have this problem. However, when I mix running tests between emulator and then real device, app and tests appear to be running quite often. I don't really know why but maybe it will help someone. – adek111 Aug 23 '19 at 13:39
  • Maybe you can successfully rerun app on `API26+` if you click `Apply changes`, instead of `rerun`? This is new button to right of `rerun`. – mohax Aug 23 '19 at 17:01
11

Build > Clean project its work's for me. Before change other setting try this first.

Happy coding :)

happy_coding
  • 1,064
  • 1
  • 13
  • 24
7

For me either uninstalling the app or cleaning project "solves" the problem. To make it less frustrating I added clean job to debug build type like so:

buildTypes {
    ...
    debug {
        clean
    }
    ...
}
Sancho
  • 220
  • 2
  • 9
6

After reading the Release Notes regarding Apply Changes, I finally found a solution here: https://developer.android.com/studio/run#apply-changes-run-fallback

Enable Run fallback for Apply Changes

After you've clicked either Apply Changes and Restart Activity or Apply Code Changes, Android Studio builds a new APK and determines whether the changes can be applied. If the changes can't be applied and would cause Apply Changes to fail, Android Studio prompts you to Run Run icon your app again instead. However, if you don't want to be prompted every time this occurs, you can configure Android Studio to automatically rerun your app when changes can't be applied.

To enable this behavior, follow these steps:

  1. Open the Settings or Preferences dialog:
    • On Windows or Linux, select File > Settings from the menu bar.
    • On macOS, select Android Studio > Preferences from the menu bar.
  2. Navigate to Build, Execution, Deployment > Deployment.
  3. Select the checkboxes to enable automatic Run fallback for either of the Apply Changes actions.
  4. Click OK.

Screenshot running on Linux

4

There is a problem with Lineage OS as stated by Google team in https://issuetracker.google.com/issues/139782879:

We are able to reproduce it on a device with LineageOS. It does not fully support a system call that we use for DeltaInstall.

There is no apparent solution (other than removing the APK from build folder or uninstalling the application).

We should have a workaround for it but as it stands right now, LineageOS will not have DeltaInstall and will always need to perform a slower full install.

Changing to Nothing as pointed out by OP will not deploy the APK to the device (that's why an error will not be displayed), so it will not solve the problem.

Edit:

This has been fixed in Android Studio 3.6.

Thanks for the feedback. This should be fixed in the latest versions of 3.6.

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
3

I got the solution in the code edit run configuration changing in Deploy select Default APK and install flag =-r -t and then Apply for the run. The app will run in all devices and emulator. I was testest in OPPO 1 plus, Samsung Tab, Emulator Also.

Please Go thought the Edit Run configuration near to run button in Android Studio

edit app > general ==> installation options ==> Install flags

add install flags -r -t

-r means "replace existing application". -t means "allow test packages"

enter image description here

3

1-clean project from Build -> CleanProject

2-delete folder outputs from ProjectPath/app/build/outputs

3-then build gradle and run app

2

I too am having this same problem after upgrading to 3.5. I was wondering if you have had any luck getting 'Run' to work with a connected device?

UPDATE: I was am to get this to work by Setting "APK from app bundle" under Installation Options in the "Run/Debug Configurations" dialog

Chooven
  • 105
  • 5
2

I also got this error when I ran the application on real xiaomi pocophone 1 and solved this problem by running the application first on the emulator, and then on my xiaomi pocophone 1

ch13mob
  • 261
  • 6
  • 11
2

I got this because the device was locked and required user to accept permissions in order to install it. (Huawei Harmony OS)

Unlocking the phone to prepare for the installation process solved the issue.

htafoya
  • 18,261
  • 11
  • 80
  • 104
2

If your app targets Android 12 or higher, you must declare these attribution tags in your app's manifest file. If the app component includes the LAUNCHER category, set android:exported to true.

 <activity
    android:name="com.test.activity.SplashActivity"
    android:clearTaskOnLaunch="true"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:noHistory="true"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.NoActionBar"
    android:exported="true">

Also check receiver or service in Androidmanifest, if you are using any receiver or service set android:exported="true" or false according requirement.

<receiver
    android:name="com.test.receiver.ShareReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.test.fcm.android.action.broadcast" />
    </intent-filter>
</receiver>

 <service
    android:name="com.google.android.gms.tagmanager.InstallReferrerService"
    android:exported="true" />

Also update all your gradle dependency. I have updated following dependency as per requirement.

testImplementation 'junit:junit:4.13.2' 
androidTestImplementation 'androidx.test:runner:1.4.0'


androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'

Hope it will help you as well.

Kishan Thakkar
  • 619
  • 6
  • 11
1

Deleting/uninstalling the app from the device fixed the problem for me.

MaartenDev
  • 5,631
  • 5
  • 21
  • 33
Alex Sag
  • 21
  • 2
1

Add a "clean" gradle task dependency before installing/running your apks using below configuration.

project.afterEvaluate {
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def capitalizedVariant = variant.name.capitalize()
            def assembleVariantTask = project.tasks."assemble${capitalizedVariant}"
            assembleVariantTask.dependsOn clean
        }
    }
}

Copy and paste above code into your app/build.gradle file, this works for all the build variants.

In specifically, above code will be equivalent to below if you only have debug and release build types:

assembleDebug.dependsOn clean
assembleRelease.dependsOn clean
shizhen
  • 12,251
  • 9
  • 52
  • 88
1

What Worked for me to remove old application, then rerun the project. In that case old sign certificate does not bother.

Azamat Mahkamov
  • 912
  • 14
  • 18
1
splits {
    abi {
        enable true
        reset()
        include 'x86', 'armeabi-v7a','x86_64'
        universalApk true
    }
}

Due to the different constructions such as 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', and 'arm64-v8a', we have to add the configuration above into build.gradle file.

1

For me I added accidentally new BlankActivity which is inherited from Wearable Activity. Then I deleted the activity code and layout file. But I forgot to delete the wearable related tag in App Manifest.xml file. This is the main problem for someone like me.

Vadik Sirekanyan
  • 3,332
  • 1
  • 22
  • 29
Wai Yan
  • 137
  • 1
  • 9
0

At last, I found the solution

just set v2SigningEnabled true

 signingConfigs {
    release {
        v2SigningEnabled true
    }
}
yefeng
  • 111
  • 1
  • 14
0

I did not face the problem myself. However, previously we had some problems with the Instant Run of the Android Studio. I would like to suggest checking the following settings in your Android Studio and uncheck the settings to check if your code works now.

Go to the Android Studio -> Preference and then uncheck the following under the Deployments.

enter image description here

Here's what is new in Android Studio 3.5 regarding this which will help you to understand the feature better.

enter image description here

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
0

Try to run the command "adb devices", if the output is empty, then reconnect the device. This helped me with the same error. Android studio 3.5 does not determine that the device has disconnected.

0

It bug still have on my mac os, when i get new real device and try install apk from android studio 3.5 - and I find ugly way how it fix - open terminal in studio and follow:

cd app/build/outputs/apk/debug
adb install -r -t your_app_name.apk

And it need to do with each project and each device!!

Edited:

I eventually installed

Android Studio 3.6 Canary

  • it's more working version than 3.5

But stiil need add into install flags -r -t

Boken
  • 4,825
  • 10
  • 32
  • 42
nicolas asinovich
  • 3,201
  • 3
  • 27
  • 37
0

I uninstalled the app from emulator, ran and everything went back to normal

Woz
  • 350
  • 7
  • 13
0

For me minSdkVer = 22, tarSdkVer = 28,run Gradle -> app -> Tasks -> build -> clean && cleanBuildCache action, problem solved.

0

I pressed the hammer icon to rebuild the app then it installed. So I don't know? The whole android hack job platform sucks.

All that money yet google can't hire or find programmers good enough to come up with their own true operating system.

dcarl661
  • 177
  • 3
  • 9
0

In my case, it only works by disabling the APK signature verification:

$ adb shell settings put global verifier_verify_adb_installs 0

And using the -r -t flags mentioned above

Boken
  • 4,825
  • 10
  • 32
  • 42
lgallard
  • 462
  • 3
  • 10
0

I also faced the same issue , i followed the following steps 1) Clean Project 2) Rebuilt Project

This solved my problem

Vivek
  • 586
  • 6
  • 11
0

In my case, I can't solve with all of the above answers so that I find another way. Finally, I found the solution. Just find the correct drivers of phone. My development phone is Samsung Galaxy Note 2 (MODEL : GT-N7105 / Android 4.1.2). I just share my solution to how I solved it. Hope save your time.

B M
  • 1,863
  • 1
  • 25
  • 40
0

The problem occurs when you are testing a new module. First, you write it individually, and then add it to the main app. When you add it to the main app, delete your "test_app" from your phone.

0

Run -> Edit Configuration -> install flags: -r -t -> Apply -> Ok

Savita Sharma
  • 344
  • 3
  • 9
0

I got this problem a few minutes ago when I tried running my app on real device and stopped gradle build before it finished. What I just did was to uninstall the app on device and rerun the app on both AVD and real device (simultaneously) and it worked. Hope this works for you too

Richierich
  • 26
  • 3
0

Main Solution

  1. File -> Settings -> Build, Execution, Deployment -> Debugger > Disable Use libusb backend

  2. Gradle (Flap to the right of the IDE) -> android -> app -> Tasks -> install -> uninstallAll or you can also do it by console in the following way:

    $ ./gradlew uninstallAll



Other Tips:

  • Delete and create the app again in Run/Debug Configuration

    • Installation Options -> Check Install for all users
  • Run/Debug Configuration -> Launch Options > Launch: Specified Activity > Choose an Activity

  • Install app using another physical device, version of the IDE or PC

  • Reinstall IDE and delete .android

  • Retry with the main solution


If you want to install and open the app you can use adb with the following commands:

$ adb install -r -t absolute-path.apk

$ adb shell am start -n "com.package.flavor.env/.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

GL

Source

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
0

For me the issue started when I created a new blank activity and Android studio created a Wearable activity for some reason. Once I removed all mentions to wearable activity from the manifest and I deleted the class everything went back to normal.

Eddie
  • 119
  • 1
  • 5
-1

try to chang android:appComponentFactory="" to android:appComponentFactory="new","new" can be any words

help-ukraine-now
  • 3,850
  • 4
  • 19
  • 36
sh_ZJ
  • 1
-2

Finally, I got the solution in the code edit run configuration changing in Installation option DEPLOY--> from select 4th option -->(Nothing) option --> Apply And the app works properly in android studio 3.5. In mobile and emulator also. This work properly in android version 9 also This is a permanent solution.

-2

gradle.properties -> android.enableAapt2=false

sapeg
  • 109
  • 7
  • **DO NOT USE THIS!** Aapt has been deprecated in favor of aapt2, and will eventually be removed. This workaround will stop working, and cause other problems when aapt is removed – Zoe Jul 07 '20 at 11:54