有没有人遇到过可以在 Debug 模式下安装 APK 但在 Release 模式下以及 Archived 和正确 Singed 时都无法安装的应用程序?出现错误消息“解析包时出现问题”?
我能够从网络安装其他 APK,并在调试模式下为我的应用程序获取 Android 更新窗口(由于调试和发布配置冲突,我实际上无法更新应用程序)。然而,当处于发布模式或存档并签名时,我下载的包根本无法识别,即使来自其他供应商也是如此。
我会尽力消除混乱。假设您给我一个完美运行的 APK,例如 Facebook apk。如果我要求我的应用程序使用 Dropbox 链接下载 apk 并在调试模式下使用 Intent 安装它,它将成功安装!如果我在发布模式下这样做,它将失败并出现解析包的错误。我下载哪个 APK 并不重要。软件包安装仅在 Release! 中失败!这就是为什么 logcat 不会帮助我,这不是 APK 的错误,而是安装 APK 的过程。
//Download Package
string installPath = System.IO.Path.Combine(Plugin.XF.AppInstallHelper.InstallationHelper.GetPublicDownloadPath(), "facebook.apk");
using (HttpClient hc = new HttpClient())
{
var hcResponse = await hc.GetAsync(apkLink);
var byteArray = await hcResponse.Content.ReadAsByteArrayAsync();
System.IO.File.WriteAllBytes(installPath, byteArray);
}
// Create an intent to the settings page to allow installation of unknown apps
var intent = new Intent(Android.Provider.Settings.ActionManageUnknownAppSources);
intent.SetData(Android.Net.Uri.Parse("package:" + Android.App.Application.Context.PackageName));
StartActivityForResult(intent, 0);
// Install the APK file using an intent
var installIntent = new Intent(Intent.ActionView);
var file = new Java.IO.File(installPath);
file.SetReadable(true, false);
var apkUri = Android.Support.V4.Content.FileProvider.GetUriForFile(this, "com.*hidden*.fileprovider", file);
installIntent.SetDataAndType(apkUri, "application/vnd.android.package-archive");
installIntent.SetFlags(ActivityFlags.GrantReadUriPermission | ActivityFlags.NewTask);
StartActivity(installIntent);
所以这段代码在调试模式下按预期工作,但在发布模式下失败!