'Getting Parse Error when installing the .apk file
I am downloading .apk file from the server using DownloadManager after downloading when i am trying to install the app manually it is giving parse error with a message "There is a problem parsing the package".
But same apk when i am downloading through browser and copying to SD card then installing, then it is installing successfully.
So hope there is no issue with the minsdkversion and I already checked on Unknown Sources.
My Code is like this for downloading the apk file
public class UpdateCheckerService extends Service {
UpdateChecker update_checker;
DownloadManager downloadManager;
String Download_path="http://www.xxxxx.com/mobile_api/xxxxxx.apk";
SharedPreferences preferenceManager;
String Download_ID = "100";
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onCreate()
{
System.out.println("SERVICE ************ CREATED");
}
public void onStart(Intent intent1, int start_id)
{
System.out.println("Service started");
IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(downloadReceiver, intentFilter);
System.out.println("Service started");
if(isNetworkAvailable())
{
if(true)
{
System.out.println("Update AVAAILLL:");
preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.mkdirs();
Uri Download_Uri = Uri.parse(Download_path);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
long download_id = downloadManager.enqueue(request.setTitle("Downloading...")
.setDescription("xxxx").setMimeType("application/vnd.android.package-archive").setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
"xxxxx.apk"));
Editor PrefEdit = preferenceManager.edit();
PrefEdit.putLong(Download_ID, download_id);
PrefEdit.commit();
}
}
}
public void onDestroy()
{
}
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(preferenceManager.getLong(Download_ID, 0));
Cursor cursor = downloadManager.query(query);
if(cursor.moveToFirst()){
int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(columnIndex);
int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(columnReason);
if(status == DownloadManager.STATUS_SUCCESSFUL){
//Retrieve the saved download id
long downloadID = preferenceManager.getLong(Download_ID, 0);
ParcelFileDescriptor file;
try {
file = downloadManager.openDownloadedFile(downloadID);
Toast.makeText(UpdateCheckerService.this,
"File Downloaded: " + file.toString(),
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(UpdateCheckerService.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
}else if(status == DownloadManager.STATUS_FAILED){
Toast.makeText(UpdateCheckerService.this,
"FAILED!\n" + "reason of " + reason,
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_PAUSED){
Toast.makeText(UpdateCheckerService.this,
"PAUSED!\n" + "reason of " + reason,
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_PENDING){
Toast.makeText(UpdateCheckerService.this,
"PENDING!",
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_RUNNING){
Toast.makeText(UpdateCheckerService.this,
"RUNNING!",
Toast.LENGTH_LONG).show();
}
}
}
};
}
Here is the logcat
11-25 16:31:58.195: D/asset(3422): failed to open Zip archive '/mnt/sdcard/Download/SavariLocal.apk'
11-25 16:31:58.210: W/PackageParser(3422): Unable to read AndroidManifest.xml of /mnt/sdcard/Download/SavariLocal.apk
11-25 16:31:58.210: W/PackageParser(3422): java.io.FileNotFoundException: AndroidManifest.xml
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlAssetNative(Native Method)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:486)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:454)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.pm.PackageParser.parsePackage(PackageParser.java:402)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.packageinstaller.PackageUtil.getPackageInfo(PackageUtil.java:79)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:242)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-25 16:31:58.210: W/PackageParser(3422): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 16:31:58.210: W/PackageParser(3422): at android.os.Looper.loop(Looper.java:130)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-25 16:31:58.210: W/PackageParser(3422): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 16:31:58.210: W/PackageParser(3422): at java.lang.reflect.Method.invoke(Method.java:507)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-25 16:31:58.210: W/PackageParser(3422): at dalvik.system.NativeStart.main(Native Method)
11-25 16:31:58.210: W/PackageInstaller(3422): Parse error when parsing manifest. Discontinuing installation
Please suggest me how to fix this issue, and where i am wrong..
Thanks in advance.
Solution 1:[1]
I had the same issue and I found out that after uninstalling the app and than reinstall the apk helped.
There is another solution that I did not try but it might be useful.
Solution 2:[2]
I faced this issue previously. This is how I debugged it. First, install the APK through terminal adb install path_to_your_app/name_of_your_app.apk if you get error message: adb: failed to install name_of_your_app.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries this means that the architecture that you are building mismatches with the emulator architecture.
Since this is an APK from external source, you may want to look into repackaging it and build according to your device architecture.You could use this tool: https://ibotpeaches.github.io/Apktool/
Hope this helps
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 | Shai |
Solution 2 | Angie |