8

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.

morpheus
  • 18,676
  • 24
  • 96
  • 159
  • have you uninstalled your debug build app? – nandeesh Jan 10 '12 at 07:05
  • yes I have uninstalled debug build – morpheus Jan 10 '12 at 07:09
  • just install the unsigned apk. – Padma Kumar Jan 10 '12 at 07:31
  • There may be an issue with your certificate. Try generating a new one. Also try installing release version both on device and on emulator, if error is consistent, than this is not a device glitch. – inazaruk Jan 10 '12 at 07:43
  • This can be caused by an error in your AndroidManifest.xml file (for instance, if your version code isn't an integer, as described [here](https://groups.google.com/forum/#!topic/android-beginners/LxgAIHETEWg).) – Ted Hopp Jan 10 '12 at 07:48

4 Answers4

11

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"
Max Worg
  • 2,932
  • 2
  • 20
  • 35
6

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

Community
  • 1
  • 1
morpheus
  • 18,676
  • 24
  • 96
  • 159
1

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.

Yoav Feuerstein
  • 1,925
  • 2
  • 22
  • 53
0

Found answer in this one. https://github.com/flutter/flutter/issues/96497

AndroidManifest.xml is missing one line of code:

android:exported="true"

<activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:exported="true" -> this is the missing line of code
        android:windowSoftInputMode="adjustResize"
        >
petras J
  • 2,538
  • 3
  • 16
  • 23