Xamarin Android应用在发布模式下崩溃Android SDK)

本文关键字:Android 模式 崩溃 SDK 应用 布模式 Xamarin | 更新日期: 2023-09-27 18:05:13

我正在开发使用Parse Android SDK的应用程序。应用程序在调试模式下正常工作,但当我在发布模式上编译它时,我得到以下错误。执行解析查询时发生错误。

[MonoDroid] UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
[MonoDroid]   at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0 
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
[MonoDroid]   at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0 
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
[MonoDroid]   at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0 
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
[MonoDroid]   at System.Runtime.CompilerServices.TaskAwaiter`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]].GetResult () [0x00000] in <filename unknown>:0 
[MonoDroid]   at ParseDAL.ParseCaller+<Init>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
[mono] 
[mono] Unhandled Exception:
[mono] System.NullReferenceException: Object reference not set to an instance of an object
[mono]   at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0 
[mono] --- End of stack trace from previous location where exception was thrown ---
[mono]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
[mono]   at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0 
[mono]   at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0 
[mono]   at System.Threading.Tasks.Task.InnerInvoke 
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
[mono-rt]   at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0 
[mono-rt] --- End of stack trace from previous location where exception was thrown ---
[mono-rt]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
[mono-rt]   at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0 
[mono-rt]   at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0 
[mono-rt]   at System.Threading.Tasks.Task

代码如下:

ParseClient.Initialize("App Id", "Dot Net Key");
var userQuery = ParseObject.GetQuery ("Table Name");
var userData = await userQuery.FindAsync ();
foreach (var ud in userData) {
    Console.WriteLine ("UD " + ud.Get<string>(Constants.COL_USER_NAME));
}

我尝试了所有链接器选项"不链接","链接所有组件","链接SDK组件"。但是程序还是崩溃了

Xamarin Android应用在发布模式下崩溃Android SDK)

这个异常的发生是因为网络问题而不是因为调试/发布版本。在调试模式下,INTERNET权限会自动添加到manifest文件中,但在发布模式下不会。所以在manifest文件中添加这个权限。

<uses-permission android:name="android.permission.INTERNET" />

之后的异常在释放模式下不会发生。

在发送请求解析之前,我们仍然需要检查网络是否可用。