title: how to fix parse error in lollipop while installing apk
body: <p>I have an application which will download the other apks from our server and install it one by one.
  This works fine in versions lower than lollipop 5.0 , but in case of lollipop devices it is giving parse error.
  I have also checked the option of installing apk from unknown sources in device.
  the  detailed warnings in logcat while installing apk is :</p>
  
  <p>Zip: 2 extraneous bytes at the end of the central directory</p>
  
  <p>W/zipro(5776): Error opening archive /data/local/tmp/XYZ.apk: Invalid file</p>
  
  <p>D/asset(5776): failed to open Zip archive '/data/local/tmp/XYZ.apk'</p>
  
  <p>W/DefContainer(5776): Failed to parse package at /data/local/tmp/XYZ.apk: android.content.pm.PackageParser$PackageParserException:
   Failed to parse /data/local/tmp/XYZ.apk</p>
  
  <p>The things I tried and results are as follows,</p>
  
  <p>1.Create fresh new apk and push it via adb into device and try to install -  <strong>Install successfull.</strong></p>
  
  <p>2.After that upload that same apk to server , download it from browser[ not through application ]-<strong>failed “[INSTALL_FAILED_INVALID_APK]</strong> </p>
  
  <p>3.I have implemented the MD5 checksum for validating the apk download , checksum is also fine.</p>
  
  <p>4.If I again sign the downloaded apk or zip align the apk [ Effectively repackage apk ] and try to install -<strong>Install successfull.</strong></p>
  
  <p>Please help me , how to fix this issue.</p>
  
  <p>permissions in Manifest : </p>
  
  <pre><code>&lt;uses-sdk
          android:minSdkVersion="9"
          android:targetSdkVersion="22" /&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.INSTALL_PACKAGES" /&gt;
      &lt;uses-permission android:name="android.permission.DELETE_PACKAGES" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
      &lt;uses-permission android:name="android.permission.NFC" /&gt;
      &lt;uses-permission android:name="android.permission.REBOOT" /&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_APN_SETTINGS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SETTINGS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /&gt;
      &lt;uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" /&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /&gt;
      &lt;uses-permission android:name="android.permission.SET_TIME" /&gt;
      &lt;uses-permission android:name="android.permission.SET_TIME_ZONE" /&gt;
  </code></pre>