简体   繁体   中英

Inconsistent Parsing Error when trying to install an unsigned remote .apk file

I'm currently working on an app that will not go on the play store and needed some sort of update routine.

I got it working so when the user presses a button the app downloads an apk file hosted on one of our servers. That part works fine. Here's the interesting stuff...

When I try to start the intent to install the file, I get the following parse error:

"Parse Error There is a problem parsing the package"

This error happens everytime no matter what on android version 4.0.3. Here is the logcat:

10-03 18:36:05.212: D/asset(567): failed to open Zip archive            '/mnt/sdcard/download/AMWireless.apk'
10-03 18:36:05.272: W/PackageParser(567): Unable to read AndroidManifest.xml of     /mnt/sdcard/download/AMWireless.apk
10-03 18:36:05.272: W/PackageParser(567): java.io.FileNotFoundException:  AndroidManifest.xml
10-03 18:36:05.272: W/PackageParser(567):   at android.content.res.AssetManager.openXmlAssetNative(Native Method)
10-03 18:36:05.272: W/PackageParser(567):   at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487)
10-03 18:36:05.272: W/PackageParser(567):   at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:455)
10-03 18:36:05.272: W/PackageParser(567):   at android.content.pm.PackageParser.parsePackage(PackageParser.java:425)
10-03 18:36:05.272: W/PackageParser(567):   at com.android.packageinstaller.PackageUtil.getPackageInfo(PackageUtil.java:74)
10-03 18:36:05.272: W/PackageParser(567):   at com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:277)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.Activity.performCreate(Activity.java:4465)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-03 18:36:05.272: W/PackageParser(567):   at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 18:36:05.272: W/PackageParser(567):   at android.os.Looper.loop(Looper.java:137)
10-03 18:36:05.272: W/PackageParser(567):   at android.app.ActivityThread.main(ActivityThread.java:4424)
10-03 18:36:05.272: W/PackageParser(567):   at java.lang.reflect.Method.invokeNative(Native Method)
10-03 18:36:05.272: W/PackageParser(567):   at java.lang.reflect.Method.invoke(Method.java:511)
10-03 18:36:05.272: W/PackageParser(567):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-03 18:36:05.272: W/PackageParser(567):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-03 18:36:05.272: W/PackageParser(567):   at dalvik.system.NativeStart.main(Native Method)
10-03 18:36:05.272: W/PackageInstaller(567): Parse error when parsing manifest. Discontinuing installation

Yet, my updater works on my droid x2 running version 2.3.5. The intent to install the app goes great and once they confirm the app permissions it installs.

I was able to reproduce the parse error on version 2.3.5 here is how:

I normally just install the app through eclipse, by running it, but if I right-clicked on the package in the package explorer window used android tools to export an unsigned .apk, and tried to install the package manually it would not install.

If I use the .apk's that are in the project bin folder, it installs fine and updates fine on 2.3.5

Here is the asynctask class I use:

public class UpdateWireless extends AsyncTask<String,Void,String>{
private Context context;
public void setContext(Context contextf){
context = contextf;
}
@Override
protected String doInBackground(String... arg0) {
try {
URL url = new URL(arg0[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/";
File oldFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/AMWireless.apk");
if(oldFile.exists())
{
oldFile.delete();
}
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "AMWireless.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e){
}
return "File Saved";
}
protected void onPostExecute(String result) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new      File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/"+"AMWireless.apk")), "application/vnd.android.package-archive");
startActivity(intent); 
}

}

and yes I need to but something in the catch block but we will get there...

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wireless.wmaa"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />    
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
    <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
                                     >
        <activity
            android:label="@string/app_name"
            android:name=".SelectServer" 
            android:theme="@android:style/Theme.NoTitleBar"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /> 
             </intent-filter>"
            </activity>
        <activity
            android:name=".UpdateApp"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar"
            android:screenOrientation="landscape" >  
            <intent-filter>
            </intent-filter>
        </activity>

        <activity
            android:name=".WirelessActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar"
            android:screenOrientation="landscape" >  
            <intent-filter>
            </intent-filter>
        </activity>
    </application>


</manifest>

Am I Exporting things from Eclipse wrong? Is it a manifest issue? Am I going about this right?

EDIT 1: Alright narrowed it down a little more to a problem with this line on the android 4.0.3:

InputStream is = c.getInputStream();

This line throws a file not found exception, as in it can't see the file on my server and it is never downloads. Android 2.3.5 sees the file has no exceptions and downloads the and installs fine... Whats the problem here?

EDIT 2: RESOLVED I was originally trying to host the file on a site that was served by IIS, and the old version of android didn't care, but the new version would not see the file. Once I moved the .apk to a web server running apache I had no issues. So, something is fishy with IIS or maybe my configuration of it....

Answered my own question. Was a problem with where I was hosting the file. IIS and android would not play nice together :( solution: move .apk file to apache server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM