Installation failed due to: 'null' - Android Studio 3.5

浪子不回头ぞ 提交于 2019-11-28 15:44:06

问题


I have updated Android studio to 3.5, ever since I am running into 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 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 reasons 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 maybe originating on Windows machines.


回答1:


Open Run/Debug Configuration dialog

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

add install flags -r -t.

This flags means adb install -r -t apkpath




回答2:


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.




回答3:


You need disable "Use libusb backend" in preferences--> debugger




回答4:


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
    }
    ...
}



回答5:


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"




回答6:


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.




回答7:


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.




回答8:


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




回答9:


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




回答10:


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.




回答11:


At last, I found the solution

just set v2SigningEnabled true

 signingConfigs {
    release {
        v2SigningEnabled true
    }
}



回答12:


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




回答13:


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.

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




回答14:


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



回答15:


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.




回答16:


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




回答17:


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!!

p.s. Google, realy???

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




回答18:


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




回答19:


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




回答20:


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




回答21:


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.



来源:https://stackoverflow.com/questions/57589248/installation-failed-due-to-null-android-studio-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!