Xamarin表单,在Visual Studio Android Emulator上运行的应用程序但在真实设备上崩溃

曾无好事来相访,赖尔高文一起予。这篇文章主要讲述Xamarin表单,在Visual Studio Android Emulator上运行的应用程序但在真实设备上崩溃相关的知识,希望能为你提供帮助。
我已经创建了一个应用程序,当构建应用程序在Visual Studio模拟器上运行完美。所以我创建了发布版本并尝试在我的物理android设备上运行应用程序。我在设备上收到以下错误消息。我用过Xam.plugin.media

android.runtime.javaProxyThrowable:System.NullReferenceException:对象引用未设置为Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage(Xamarin.Forms.Page页面)[0x0006f]中的对象实例:Xamarin.Forms中的0 .Platform.Android.FormsAppCompatActivity.SetMainPage()[0x0000c] in:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication(Xamarin.Forms.Application application)[0x0025c] in:0 at InterestMatch.Droid.MainActivity.OnCreate (Android.OS.Bundle包)[0x00033]在< 9e2a066af7c24de6828dc3a0f4e22d31> :0,在Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_(System.IntPtr jnienv,System.IntPtr native__this,System.IntPtr native_savedInstanceState)[0x0000f] in < 1e89c43d3c7d48b5ba69bfc0b1bdf114> :0 at(wrapper dynamic-method)System.Object:6b534aff-3541-46f2-a92e-ac0022b9c4a7(intptr,intptr,intptr)at md5ed93386354f0e17f050b2885712023ca.MainActivity.n_onCreate(Native Method)at md5ed93386354f0e17f050b2885在Android.app.ActivityThread.performLaunchActivity的android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)的android.app.Activity.performCreate(Activity.java:6303)712023ca.MainActivity.onCreate(MainActivity.java:29) (ActivityThread.java:2402)在android.app.A活动时,Android.app.A活动(活动传递。 .java:1373)在android.app.A.运行时,android.O.Ra上的android.O.Roper.loop(Looper.java:154)的android.os.Handler.dispatchMessage(Handler.java:102)。(ActivityThread.java:5523) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:739)的com.android.internal.os.ZygoteInit.main(ZygoteInit。)中的java.lang.reflect.Method.invoke(Native Method)。 Java的:629)
这是我的代码
MainActivity.cs
public class MainActivity global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); }public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults) { PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults); }}

app.xaml.cs
using InterestMatch.Inter; using InterestMatch.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Xamarin.Auth; using Xamarin.Forms; namespace InterestM { public partial class App : Application {public static string AppName { get { return "StoreAccountInfoApp"; } }public static ICredentialsService CredentialsService { get; private set; }public App () { var account = AccountStore.Create().FindAccountsForService(App.AppName).FirstOrDefault(); CredentialsService = new CredentialsService(); if (CredentialsService.DoCredentialsExist()) { InitializeComponent(); MainPage = new NavigationPage(new InterestM.MainMenu(account.Username.ToString())); } else { InitializeComponent(); MainPage = new NavigationPage(new InterestM.Accounts.Login()); }}protected override void OnStart () { // Handle when your app starts }protected override void OnSleep () { // Handle when your app sleeps }protected override void OnResume () { // Handle when your app resumes } }

}
答案更改Android项目选项为我解决了这个问题。
【Xamarin表单,在Visual Studio Android Emulator上运行的应用程序但在真实设备上崩溃】打开Android项目的属性。转到Android选项。将链接属性更改为“仅限Sdk程序集”。

    推荐阅读