尝试安装未签名的远程.apk文件时出现不一致的解析错误
我目前正在开发一款不会在Play商店上架并且需要某种更新例程的应用程序.
I'm currently working on an app that will not go on the play store and needed some sort of update routine.
我可以正常运行,因此当用户按下按钮时,应用程序将下载一个托管在我们服务器之一上的apk文件.那部分工作正常.这是有趣的东西...
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"
无论在Android版本4.0.3上是什么,每次都会发生此错误.这是logcat:
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
但是,我的更新程序可以在运行版本2.3.5的droid x2上使用.安装该应用程序的意图非常棒,一旦他们确认了该应用程序的安装权限即可.
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.
我能够在2.3.5版中重现解析错误,方法如下:
I was able to reproduce the parse error on version 2.3.5 here is how:
我通常只是通过运行eclipse来安装应用程序,但是如果我在软件包资源管理器"窗口中右键单击该软件包,则使用android工具导出未签名的.apk,并尝试手动安装该软件包安装.
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.
如果我使用项目bin文件夹中的.apk,则可以正常安装并在2.3.5上更新
If I use the .apk's that are in the project bin folder, it installs fine and updates fine on 2.3.5
这是我使用的asynctask类:
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);
}
}
是的,我需要在catch块中添加一些东西,但是我们会到达那里...
and yes I need to but something in the catch block but we will get there...
这是我的清单:
<?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>
我从Eclipse导出内容是否错误?这是明显的问题吗?我要这样做吗?
Am I Exporting things from Eclipse wrong? Is it a manifest issue? Am I going about this right?
好吧,将其缩小到Android 4.0.3上此行的问题:
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();
此行引发文件未找到异常,因为它在我的服务器上看不到该文件,并且从不下载. Android 2.3.5看到文件没有异常,然后下载并安装正常...这里出了什么问题?
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?
已解决 我最初试图将文件托管在IIS服务的网站上,而旧版本的android不在乎,但是新版本将看不到该文件.将.apk移到运行apache的Web服务器后,我就没有问题了.因此,IIS或我的配置有些混乱....
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....
回答了我自己的问题.我在哪里托管文件时出现问题. IIS和android不能很好地配合使用:(解决方案:将.apk文件移动到apache服务器.
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.