'java.lang.IllegalArgumentException: Error: Failed to parse APK file:

I have search stockoverflow and google with no luck. I recently migrated my app to androidx, after a lot of effort I was able to fix all the build fails. but now I am getting the following error when the app is installing on the emulator or the device. any help will be highly appreciated.

I have tried the following: invalidate caches/restart clean build and rebuild project uninstalled app from the device restarted my pc

Exception occurred while executing:
java.lang.IllegalArgumentException: Error: Failed to parse APK file: /data/local/tmp/...
    at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:338)
    at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:906)
    at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:158)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:21328)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2821)
    at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3856)
    at android.os.Binder.execTransact(Binder.java:731)
Caused by: android.content.pm.PackageParser$PackageParserException: Failed to parse /data/local/tmp/...
    at android.content.pm.PackageParser.parseApkLiteInner(PackageParser.java:1590)
    at android.content.pm.PackageParser.parseApkLite(PackageParser.java:1575)
    at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:331)
    ... 9 more
$ adb shell pm uninstall ...
Unknown failure (at android.os.Binder.execTransact(Binder.java:731))
Error while Installing APK


Solution 1:[1]

Delete the previous app-release.apk file from the android folder:

\app\build\outputs\apk\release

Then clear all data from the emulator. Finally, rebuild the application.

Solution 2:[2]

Clean -> Rebuild -> and try to check both v1 and v2 while generating apk file

Solution 3:[3]

You should drop the cache on your mobile. for example:

1- open your windows terminal on your computer

2 - enter the command >adb shell you should be insite on your mobile

3 - enter to the tmp/appium_cache/ folder with >cd data/local/tmp/appium_cache

4 - write the command >ls to see all the elements that there is insite of that folder

5 - drop all that elements with the command >rm filename

hope to help you

Solution 4:[4]

just delete build folder and run again

android/app/build

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Uma Achanta
Solution 3 Rogelio Velazquez Hernandez
Solution 4 sherkhan