如何解决Xamarin Android链接问题 [英] How to resolve Xamarin Android linking problem

查看:172
本文介绍了如何解决Xamarin Android链接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Xamarin Forms Android应用程序在Debug中可以正常工作.但是在Release中,将其部署到仿真器或设备时,在显示初始屏幕后将停止"该应用程序.调试日志显示这些错误,表明找不到类FitWindowsLinearLayout ...

My Xamarin Forms Android app works fine in Debug. But in Release, when deployed to either the emulator or to a device, the app is "stopped" after showing the splash screen. The debug log shows these errors, indicating that it can't find class FitWindowsLinearLayout...

10-23 22:24:59.270 14008 14008 E AndroidRuntime:由以下原因引起: android.view.InflateException:二进制XML文件第14行:二进制XML 文件行#14:错误夸大类 android.support.v7.widget.FitWindowsLinearLayout

10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class android.support.v7.widget.FitWindowsLinearLayout

10-23 22:24:59.270 14008 14008 E AndroidRuntime:由以下原因引起: android.view.InflateException:二进制XML文件第14行:错误 膨胀类android.support.v7.widget.FitWindowsLinearLayout

10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.widget.FitWindowsLinearLayout

10-23 22:24:59.270 14008 14008 E AndroidRuntime:由以下原因引起: java.lang.ClassNotFoundException:找不到类 路径上的"android.support.v7.widget.FitWindowsLinearLayout": DexPathList [[zip文件 "/data/app/zeemerix.NflCalcXF-1/base.apk"],nativeLibraryDirectories=[/data/app/zeemerix.NflCalcXF-1/lib/arm, /data/app/zeemerix.NflCalcXF-1/base.apk!/lib/armeabi-v7a、/system/lib, /vendor/lib]]

10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsLinearLayout" on path: DexPathList[[zip file "/data/app/zeemerix.NflCalcXF-1/base.apk"],nativeLibraryDirectories=[/data/app/zeemerix.NflCalcXF-1/lib/arm, /data/app/zeemerix.NflCalcXF-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]

更改链接到无"可以解决此问题,但APK很大. 我应该使用跳过链接程序集"吗?如果是这样,输入什么?

Changing Linking to "None" resolves the problem, but then the APK is very large. Should I use "Skip Linking Assemblies"? If so, what to enter?

我尝试使用Proguard配置文件,但是当我这样做时,MainPage会显示为空白屏幕,并且调试日志说它找不到Help_ObClick(),后者是MainPage代码后面的事件处理程序.我使用的个人资料是这个...

I tried using a Proguard profile, but when I do, then the MainPage appears as a blank screen, and the debug log says it can't find Help_ObClick(), which is an event handler in the MainPage code behind. The profile I used is this...

-dontobfuscate
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space

我的Android选项:

My Android Options:

关闭:使用共享运行时 开启:启用Proguard 开启:启用开发人员检测 链接:SDK和用户程序集[将其设置为None可以解决问题]

Off: Use shared runtime On: Enable Proguard On: Enable developer instrumentation Linking: Sdk and User Assemblies [Setting it to None resolves problem]

使用Android版本编译:8.1 最低Android版本:7.0 目标Android版本:8.1

Compile using Android version: 8.1 Min Android version: 7.0 Target Android version: 8.1

我的设置:

VS社区2017,版本15.7.3 Xamarin 4.10.10.1 Xamarin Android SDK 8.3.3.2 Xamarin表格3.3.0.912540 Xamarin支持库v27.0.2.1

VS Community 2017, Version 15.7.3 Xamarin 4.10.10.1 Xamarin Android SDK 8.3.3.2 Xamarin Forms 3.3.0.912540 Xamarin support libraries v27.0.2.1

推荐答案

您知道链接无"的工作原理,然后尝试链接仅SDK程序集" 如果这不起作用,则可以进入构建文件夹,复制所有程序集的所有名称减去扩展名,然后将其添加到跳过链接程序集"字段中

As you know linking 'None' works, try then linking 'Sdk Assemblies Only' If that doesn't work, then you can go into your build folder, copy all the names of all the assemblies minus extension and add them to the "Skip linking assemblies" field

然后将链接设置为"SDK和用户程序集",然后重试. 这将花费很长时间,但是随后将这些文件从列表中删除,直到找到导致问题的文件为止.

Then set linking to 'Sdk and User Assemblies' and try again. It will take forever but then remove each of these files from the list until you find the one(s) that cause the problem.

对我来说,因为仅链接仅SDK程序集"有效,所以我可以消除这里找到的所有SDK程序集.

For me it was much easier as Link 'Sdk Assemblies Only' worked so i could eliminate all the Sdk assemblies found here:

https://docs.microsoft.com/en-us/xamarin/cross-platform/internals/available-assemblies

用户列表要小得多,因此消除过程要快得多...

The user list was much smaller and thus process of elimination much quicker...

首先,使用反射的库通常是一个问题,因为在编译之前很难将它们识别为已使用并被标记为删除. 以我为例,它是Json.Net,RestSharp等.

Fwiw, libraries that use reflection are often a problem as they cant be easily identified as used before compile and get marked for delete. In my case it was Json.Net, RestSharp and the like....

我发布的应用程序大小仅为原本的三分之一...

My published app size is only a third what it would have been otherwise...

这篇关于如何解决Xamarin Android链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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