Home » Android » Android: Unable to install release build onto emulator; getting Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION]

Android: Unable to install release build onto emulator; getting Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION]

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am able to install a debug build onto emulator doing:

ant debug install

but am unable to install a release build. My steps:

1. ant release
2. jarsigner -verbose -keystore ..\my-release-key.keystore bin\myapp-release-unsigned.apk mykey
3. ren bin\myapp-release-unsigned.apk bin\myapp-release-signed.apk
4. zipalign -v 4 myapp-release-signed.apk myapp-release.apk
5. adb install bin\myapp-release.apk

All steps run successfully except the last one where I get a message:

82 KB/s (388012 bytes in 4.613s)
        pkg: /data/local/tmp/myapp-release.apk
Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION]

I have also tried doing ant installr instead of adb install bin\myapp-release.apk with the same result

EDIT: I think this has to do with the key, since that is the only difference I can see between release and debug builds. I generated the key using:

keytool -genkey -v -keystore my-release-key.keystore
-alias alias_name -keyalg RSA -keysize 2048 -validity 10000

as mentioned on http://developer.android.com/guide/publishing/app-signing.html. I modified ant.properties file per http://developer.android.com/guide/developing/building/building-cmdline.html and now just doing ant release install (instead of the steps above) but still running into same problem. If someone knows how does ant generate the debug key, then I could follow same procedure to generate my release key and see if that solves the problem.

How to&Answers:

I had this same issue because I was using a string value in my AndroidManifest.xml file like this:

android:versionCode="@string/version_code"
android:versionName="@string/version_name"

Where strings.xml contained:

<string name="version_code">3</string>
<string name="version_name">1.0</string>

versionCode should be an integer. Once I took out that @string reference I no longer got this error and the application compiled and ran just fine:

android:versionCode="3"
android:versionName="1.0"

Answer:

Solution: https://stackoverflow.com/a/8225017/147530
Notes:
1. I was getting a INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION. I did not get a INSTALL_PARSE_FAILED_NO_CERTIFICATES
2. Running adb logcat from cmd line showed stacktrace similar to that in Android signing with Ant:

W/PackageParser(   51): Exception reading /data/app/vmdl24231.tmp
W/PackageParser(   51): java.lang.SecurityException: META-INF/METALLIC.SF has in
valid digest for assets/myasset.xtx in /data/app/vmdl24231.tmp
W/PackageParser(   51):         at java.util.jar.JarVerifier.verifyCertificate(J
arVerifier.java:370)
W/PackageParser(   51):         at java.util.jar.JarVerifier.readCertificates(Ja
rVerifier.java:273)
W/PackageParser(   51):         at java.util.jar.JarFile.getInputStream(JarFile.
java:416)
W/PackageParser(   51):         at android.content.pm.PackageParser.loadCertific
ates(PackageParser.java:317)
W/PackageParser(   51):         at android.content.pm.PackageParser.collectCerti
ficates(PackageParser.java:479)
W/PackageParser(   51):         at com.android.server.PackageManagerService.inst
allPackageLI(PackageManagerService.java:4287)
W/PackageParser(   51):         at com.android.server.PackageManagerService.acce
ss$1600(PackageManagerService.java:109)
W/PackageParser(   51):         at com.android.server.PackageManagerService$5.ru
n(PackageManagerService.java:3779)
W/PackageParser(   51):         at android.os.Handler.handleCallback(Handler.jav
a:587)
W/PackageParser(   51):         at android.os.Handler.dispatchMessage(Handler.ja
va:92)
W/PackageParser(   51):         at android.os.Looper.loop(Looper.java:123)
W/PackageParser(   51):         at android.os.HandlerThread.run(HandlerThread.ja
va:60)

References:
http://code.google.com/p/android/issues/detail?id=19567

Answer:

I had the same error, but when I looked in logcat while trying to install the apk file to the phone, I’ve seen these lines:

11-10 11:28:26.971 20075 20085 D : Zip: EOCD not found,
/data/local/tmp/myapp.apk is
not zip

11-10 11:28:26.972 20075 20085 W zipro : Error opening archive
/data/local/tmp/myapp.apk:
Invalid file

11-10 11:28:26.972 20075 20085 D asset : failed to open Zip archive
‘/data/local/tmp/myapp.apk’

11-10 11:28:26.972 20075 20085 W DefContainer: Failed to parse package
at /data/local/tmp/myapp.apk:
android.content.pm.PackageParser$PackageParserException: Failed to
parse
/data/local/tmp/myapp.apk

As mentioned in another question, turned out the apk file was corrupted (probably didn’t download correctly), so I had to download it again, then it worked fine.