【问题标题】:App crashes in release mode and not in debug mode - Xamarin Forms应用程序在发布模式下而不是在调试模式下崩溃 - Xamarin Forms
【发布时间】:2015-11-25 03:45:36
【问题描述】:

我正在构建一个跨平台应用程序,我想将它发布给测试人员,但是当我在发布模式下部署它时它不起作用。至于例外情况,我没有得到任何。如问题中所述,它在调试模式下工作。该应用程序只是进入闪屏并崩溃。我通过测试精灵运行了原始应用程序并得到了这个异常:

    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    ... 2 more
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.IO.FileNotFoundException: Could not load file or assembly '<Censored: Name of forms class library>.dll' or one of its dependencies. The system cannot find the file specified.
File name: '<Censored: Name of forms class library>.dll'
  at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x00000] in :0 
  at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:Load (System.Reflection.AssemblyName)
  at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in :0 
  at Xamarin.Forms.Xaml.XamlParser.GetElementType (Xamarin.Forms.Xaml.XmlType xmlType, IXmlLineInfo xmlInfo, System.Reflection.Assembly currentAssembly, Xamarin.Forms.Xaml.XamlParseException& exception) [0x00000] in :0 
  at (wrapper delegate-invoke) :invoke_Type_XmlType_IXmlLineInfo_Assembly_XamlParseException& (Xamarin.Forms.Xaml.XmlType,System.Xml.IXmlLineInfo,System.Reflection.Assembly,Xamarin.Forms.Xaml.XamlParseException&)
  at Xamarin.Forms.Xaml.XamlTypeResolver.Resolve (System.String qualifiedTypeName, IServiceProvider serviceProvider, Xamarin.Forms.Xaml.XamlParseException& exception) [0x00000] in :0 
  at Xamarin.Forms.Xaml.XamlTypeResolver.TryResolve (System.String qualifiedTypeName, System.Type& type) [0x00000] in :0 
  at Xamarin.Forms.Xaml.ExpandMarkupsVisitor+MarkupExpansionParser.Parse (System.String match, System.String& remaining, IServiceProvider serviceProvider) [0x00000] in :0 
  at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.ParseExpression (System.String& expression, IXmlNamespaceResolver nsResolver, IXmlLineInfo xmlLineInfo, INode node, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.Visit (Xamarin.Forms.Xaml.MarkupNode markupnode, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.MarkupNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.RootNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0 
  at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.String xaml) [0x00000] in :0 
  at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.Type callingType) [0x00000] in :0 
  at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[LoginPage] (<Censored>.Login.LoginPage view, System.Type callingType) [0x00000] in :0 
  at <Censored>.Login.LoginPage.InitializeComponent () [0x00000] in :0 
  at <Censored>.Login.LoginPage..ctor () [0x00000] in :0 
  at <Censored>.App.b__0 () [0x00000] in :0 
  at <Censored>.ViewFactory.Resolve[LoginViewModel] (<Censored>.Login.LoginViewModel viewModel) [0x00000] in :0 
  at <Censored>.App..ctor () [0x00000] in :0 
    at md5b406f03a919343acc4f3b337a44e1248.MainActivity.n_onCreate(Native Method)
    at md5b406f03a919343acc4f3b337a44e1248.MainActivity.onCreate(MainActivity.java:28)
    at android.app.Activity.performCreate(Activity.java:5458)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
    at android.app.ActivityThread.access$900(ActivityThread.java:174)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5593)
    ... 5 more

我无法向您展示源代码,但我已在新的测试解决方案中重现了该错误。 Here 是包含测试项目的存储库的链接。它只是一个使用 MVVM 和 Xamarin Forms 的项目。

【问题讨论】:

  • 我尝试过开启和关闭 proguard 进行编译,但都不起作用。
  • 刚刚尝试关闭链接器,仍然没有任何变化。
  • @B0nde.. 转到项目属性>Android 选项>链接器> 仅选择 sdk 组件
  • @JagadeeshGovindaraj 仅将链接器更改为 SDK 后结果相同。

标签: c# android xamarin release xamarin-forms


【解决方案1】:

如果您的解决方案在调试模式下工作,而不是在发布模式下工作,则可能是链接器存在问题。

右键单击您的特定项目(不是解决方案)-> Android 选项-> 链接器-> 在链接中选择“无”。这将包括发布库中的所有 dll。

【讨论】:

  • 我已经尝试过这个修复并且它有效......但它的缺点是 android 应用程序的 .apk 包尺寸增加了很多......超过 3 倍(从 35Mb 到超过135Mb)。
【解决方案2】:

通过手动删除整个解决方案中的所有 obj 文件夹和所有 bin 文件夹来修复它。

编辑:又回来了,现在这个修复不起作用!

【讨论】:

    猜你喜欢
    • 2018-07-01
    • 1970-01-01
    • 2018-03-22
    • 2019-09-11
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多