简体   繁体   English

尝试安装未签名的远程.apk文件时出现不一致的解析错误

[英]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. 我目前正在开发一款不会在Play商店上架的应用程序,并且需要某种更新例程。

I got it working so when the user presses a button the app downloads an apk file hosted on one of our servers. 我可以正常工作,因此当用户按下按钮时,应用程序将下载一个托管在我们服务器中的apk文件。 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. 无论在Android版本4.0.3上什么时候,都会发生此错误。 Here is the logcat: 这是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. 但是,我的更新程序可以在运行版本2.3.5的droid x2上运行。 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: 我能够在版本2.3.5上重现解析错误,方法如下:

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. 我通常只是通过运行eclipse来安装该应用程序,但是如果我在软件包浏览器窗口中右键单击该软件包,则使用android工具导出未签名的.apk,并尝试手动安装该软件包将无法安装。

If I use the .apk's that are in the project bin folder, it installs fine and updates fine on 2.3.5 如果我使用项目bin文件夹中的.apk,则可以正常安装并在2.3.5上更新。

Here is the asynctask class I use: 这是我使用的asynctask类:

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? 我从Eclipse导出内容是否错误? 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: 编辑1:好吧,将其缩小到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? Android 2.3.5看到文件没有异常,然后下载并安装正常...这是什么问题?

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. 编辑2:解决我最初试图将文件托管在IIS服务的站点上,而旧版本的android不在乎,但新版本将看不到该文件。 Once I moved the .apk to a web server running apache I had no issues. 将.apk移到运行apache的Web服务器后,我就没有问题了。 So, something is fishy with IIS or maybe my configuration of it.... 因此,IIS或我的配置有些混乱。

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. IIS和android不能很好地配合使用:(解决方案:将.apk文件移动到apache服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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