Xamarin.Android MultiDex 不适用于 <21 台设备 [英] Xamarin.Android MultiDex not working on &lt;21 devices

查看:94
本文介绍了Xamarin.Android MultiDex 不适用于 <21 台设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是最近出现的问题,老实说,我不确定哪个问题是真正的问题.上周,在更新 VS2017 和 Android 支持库后,我开始收到错误消息java.exe has exited with code 2".搜索后,似乎共识是启用 MultiDex.所以我这样做了,它在较新的手机上运行良好.但是当我尝试在 KitKat 手机上编译时,我开始丢失类异常(但仅当我使用 Android Monitor 登录时,VS 中没有异常).

This seems to be a somewhat recent problem, and I am honestly not sure which problem is the real issue. Last week, after updating VS2017 and Android Support Libraries, I started getting the error "java.exe has exited with code 2". After searching, it seemed like the consensus was to enable MultiDex. So I did that, and it worked fine on newer phones. But when I tried to compile on a KitKat phone, I started to get missing class exceptions (but only when I logged with Android Monitor, no exceptions in VS).

我关注了 此链接 关于自定义应用程序类.我正在使用正确的 bat 文件和正确的自定义类.在 21+ 上一切看起来仍然很好,但是旧设备仍然报告缺少 mono.MonoPackageManager.当我查看调试文件夹中生成的 multidex.keep 时,mono/MonoPackageManager.class 肯定在该文件中.所以我真的不知道.

I followed this link regarding custom application classes. I am using the correct bat file, and the right custom class. Everything still looks fine on 21+, but the old devices still reports that mono.MonoPackageManager is missing. When I go look at the multidex.keep generated in my debug folder, mono/MonoPackageManager.class is definitely in that file. So I really have no clue.

我生成了一个 APK,以便使用 classyshark 对其进行检查.我在那里发现了一些有趣的事情.我的方法总数大约为 30K,那么如果限制为 65K,为什么还需要 multidex?而且,我注意到 mono/MonoPackageManagerclasses2.dex 中,尽管它在我的 multidex.keep 文件中.

I generated an APK in order to inspect it with classyshark. I found a couple of interesting things there. My total number of methods is around 30K, so why is multidex even required if the limit is 65K? And also, I noticed that mono/MonoPackageManager is in classes2.dex, despite it being in my multidex.keep file.

我是否遗漏了一些明显的东西,或者 Xamarin.Android 最近是否存在一些重大错误?

Am I missing something obvious, or are there some major bugs in Xamarin.Android lately?

取得进展了吗?忽略我的项目甚至不需要 multidex 的事实,我注意到生成的 multidex.keep 文件只是一行,没有空格或任何东西.当我修改这个文件以将每个类放在一个新行上,然后使用构建操作 MainDexMainDexList 添加该文件时,一切正常.我不需要重新添加它之前抱怨的类.我尝试了多个版本的 android 构建工具(特别是 25.0.2 和 26.0.1),结果相同.我觉得很奇怪,添加新行解决了问题,但生成的文件没有新行.

Progress kind of made? Ignoring the fact that my project shouldn't even need multidex, I noticed that the multidex.keep file that was generated was only a single line with no spaces or anything. When I modified this file to put each class on a new line, then added that file with the build action MainDexMainDexList, everything works fine. I did not need to re-add the classes that it was previously complaining about. I have tried multiple versions of android build tools (specifically 25.0.2 and 26.0.1) with the same result. I think it is very strange that adding new lines fixes the issue, but the generated file does not have new lines.

推荐答案

我遇到了完全相同的问题,并通过在我的项目根文件夹中创建自定义 multidex.keep 文件并添加以下内容来解决它给它:

I had the exact same issue and resolved it by creating a custom multidex.keep file in my project root folder and adding the following to it:

 mono/MonoPackageManager.class 
 mono/MonoRuntimeProvider.class
 mono/MonoPackageManager_Resources.class
 mono/android/app/NotifyTimeZoneChanges.class
 mono/android/app/ApplicationRegistration.class

这是我的任何实际应用程序类的补充,它抱怨在运行时找不到.这解决了我的 <21 个问题(尤其是 KitKat(19)).

This is in addition to any of my actual application classes it was complaining of not finding during runtime. This solved my <21 problems (especially for KitKat(19)).

构建系统仍然会创建一个 multidex.keep 文件,但这是我自定义文件的补充,所以它似乎对我有用.

The build system still creates a multidex.keep file, but that's in addition to my custom one, so it seems to work for me.

这篇关于Xamarin.Android MultiDex 不适用于 <21 台设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆