Xamarin表单Android应用程序在启动后崩溃(启动)

时间:2016-10-31 13:14:17

标签: xamarin xamarin.android xamarin.forms xamarin-studio crash

我正在使用(IOS and Android)开发一个Xamarin Forms应用程序。
我正在尝试运行我的应用程序Android版本但不幸的是,应用程序在启动画面后崩溃。
我尝试过Emulator以及physical device(Moto G3)
我已使用最新Xamarin studio版本更新了stable。我已尝试更改工作solution directory,但同样的问题仍然存在。
我已将断点保留在SplashActivity OnCreate()中,但调试器未出现在此行中。

IDE - Xamarin Studio 6.1.1(版本17)

操作系统 - Mac OS 10.11.5

Xamarin.Android -7.0.1.3

SplashActivity.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;

namespace SampleApp.Droid
{
    [Activity(Label = "SampleApp",Theme = "@style/MyTheme.Splash", MainLauncher = true)]
    public class signup : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
        }

        protected override void OnResume()
        {
            base.OnResume();

            Task startupWork = new Task(() =>
                                        {
                                            //Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
                                            Task.Delay(5000); // Simulate a bit of startup work.
                                            //Log.Debug(TAG, "Working in the background - important stuff.");
                                        });

            startupWork.ContinueWith(t =>
                                     {
                                         //Log.Debug(TAG, "Work is finished - start Activity1.");
                StartActivity(new Intent(Application.Context, typeof(MainActivity)));
                                     }, TaskScheduler.FromCurrentSynchronizationContext());

            startupWork.Start();
        }
    }
}

MainActivity.cs

using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Acr.UserDialogs;
using Xamarin.Forms;
using Plugin.Toasts;
using XLabs.Platform.Services;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;
using XLabs.Ioc;

namespace SampleApp.Droid
{
    [Activity(Label = "SampleApp.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            UserDialogs.Init(this);             

            SetXLabsInitialization();

            LoadApplication(new App());
        }

        private void SetXLabsInitialization()
        {
            var container = new SimpleContainer();

            container.Register<IDevice>(t => AndroidDevice.CurrentDevice)
                .Register<IPhoneService>(t => t.Resolve<IDevice>().PhoneService)
                .Register<IAudioStream>(t => t.Resolve<IDevice>().Microphone)
                .Register<INetwork>(t => t.Resolve<IDevice>().Network)
                .Register<IDependencyContainer>(container);


            Resolver.SetResolver(container.GetResolver());
        }
    }


}

应用输出

Forwarding debugger port 8883
Detecting existing process
> am start -n "com.excelblaze.SampleApp/md51642ab35ccd81a05989cf18bf9b46112.signup"
> Starting: Intent { cmp=com.excelblaze.SampleApp/md51642ab35ccd81a05989cf18bf9b46112.signup }

Loaded assembly: SampleApp.Droid.dll
Loaded assembly: Mono.Android.Export.dll [External]
Loaded assembly: Xamarin.Android.Support.v4.dll [External]
Loaded assembly: Xamarin.Android.Support.Vector.Drawable.dll [External]
Loaded assembly: Xamarin.Android.Support.Animated.Vector.Drawable.dll [External]
Loaded assembly: Xamarin.Android.Support.v7.AppCompat.dll [External]
Loaded assembly: Xamarin.Android.Support.v7.RecyclerView.dll [External]
Loaded assembly: Xamarin.Android.Support.Design.dll [External]
Loaded assembly: Xamarin.Android.Support.v7.CardView.dll [External]
Loaded assembly: Xamarin.Android.Support.v7.MediaRouter.dll [External]
Loaded assembly: Xamarin.Forms.Platform.Android.dll [External]
Loaded assembly: FormsViewGroup.dll [External]
Loaded assembly: Xamarin.Forms.Core.dll [External]
Loaded assembly: Xamarin.Forms.Xaml.dll [External]
Loaded assembly: Xamarin.Forms.Platform.dll [External]
Loaded assembly: AndHUD.dll [External]
Loaded assembly: Splat.dll [External]
Loaded assembly: Acr.Support.Android.dll [External]
Loaded assembly: Acr.UserDialogs.dll [External]
Loaded assembly: Acr.UserDialogs.Interface.dll [External]
Loaded assembly: Newtonsoft.Json.dll [External]
Loaded assembly: Rg.Plugins.Popup.dll [External]
Loaded assembly: Rg.Plugins.Popup.Droid.dll [External]
Loaded assembly: Xamarin.GooglePlayServices.Basement.dll [External]
Loaded assembly: Xamarin.GooglePlayServices.Base.dll [External]
Loaded assembly: Xamarin.GooglePlayServices.Maps.dll [External]
Loaded assembly: Xamarin.Forms.Maps.Android.dll [External]
Loaded assembly: Xamarin.Forms.Maps.dll [External]
Loaded assembly: Toasts.Forms.Plugin.Abstractions.dll [External]
Loaded assembly: Toasts.Forms.Plugin.Droid.dll [External]
Loaded assembly: ExifLib.dll [External]
Loaded assembly: XLabs.Core.dll [External]
Loaded assembly: XLabs.Platform.dll [External]
Loaded assembly: XLabs.Platform.Droid.dll [External]
Loaded assembly: XLabs.Ioc.dll [External]
Loaded assembly: SampleApp.dll
Loaded assembly: XamForms.Controls.Calendar.dll [External]
Loaded assembly: Plugin.Geolocator.Abstractions.dll [External]
Loaded assembly: Plugin.Geolocator.dll [External]
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: Java.Interop.dll [External]
Loaded assembly: System.dll [External]
Loaded assembly: System.Core.dll [External]

错误/警告 - 构建输出

Build started 10/31/2016 7:20:04 PM.
__________________________________________________
Project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/UITests/SampleApp.UITests.csproj" (Build target(s)):

    Target PrepareForBuild:
        Configuration: Debug Platform: AnyCPU

    Target ResolveProjectReferences:
        Project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj" (GetTargetPath target(s)):
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj:  warning : Target '_CopyOutOfDateSourceItemsToOutputDirectory', not found in the project
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj:  warning : Target 'XapPackager', not found in the project

            Target BclBuildValidateNugetPackageReferences:
:  warning : All projects referencing SampleApp.iOS.csproj must install nuget package MSArosoft.Bcl.Build. For more information, see http://go.mSArosoft.com/fwlink/?LinkID=317569.
        Done building project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj".

        Project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/Droid/SampleApp.Droid.csproj" (GetTargetPath target(s)):

            Target BclBuildValidateNugetPackageReferences:
:  warning : All projects referencing SampleApp.Droid.csproj must install nuget package MSArosoft.Bcl.Build. For more information, see http://go.mSArosoft.com/fwlink/?LinkID=317569.
        Done building project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/Droid/SampleApp.Droid.csproj".


    Target GenerateSatelliteAssemblies:
    No input files were specified for target GenerateSatelliteAssemblies, skipping.

    Target _GenerateTargetFrameworkMonikerAttribute:
    Skipping target "_GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.

    Target CoreCompile:
    Skipping target "CoreCompile" because its outputs are up-to-date.
Done building project "/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/UITests/SampleApp.UITests.csproj".

Build succeeded.

Warnings:

/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/UITests/SampleApp.UITests.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/4.6.1/lib/mono/xbuild/14.0/bin/MSArosoft.Common.targets (ResolveProjectReferences target) ->
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj (GetTargetPath) ->

    /Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj:  warning : Target '_CopyOutOfDateSourceItemsToOutputDirectory', not found in the project
    /Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj:  warning : Target 'XapPackager', not found in the project

/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/UITests/SampleApp.UITests.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/4.6.1/lib/mono/xbuild/14.0/bin/MSArosoft.Common.targets (ResolveProjectReferences target) ->
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/iOS/SampleApp.iOS.csproj (GetTargetPath) ->
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/packages/MSArosoft.Bcl.Build.1.0.21/build/MSArosoft.Bcl.Build.targets (BclBuildValidateNugetPackageReferences target) ->

    :  warning : All projects referencing SampleApp.iOS.csproj must install nuget package MSArosoft.Bcl.Build. For more information, see http://go.mSArosoft.com/fwlink/?LinkID=317569.

/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/UITests/SampleApp.UITests.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/4.6.1/lib/mono/xbuild/14.0/bin/MSArosoft.Common.targets (ResolveProjectReferences target) ->
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/Droid/SampleApp.Droid.csproj (GetTargetPath) ->
/Users/umar_shazuli/Documents/Umar/SA/WorkingCode/SA_31_10_2016/Mobile/packages/MSArosoft.Bcl.Build.1.0.21/build/MSArosoft.Bcl.Build.targets (BclBuildValidateNugetPackageReferences target) ->

    :  warning : All projects referencing SampleApp.Droid.csproj must install nuget package MSArosoft.Bcl.Build. For more information, see http://go.mSArosoft.com/fwlink/?LinkID=317569.

     4 Warning(s)
     0 Error(s)

Time Elapsed 00:00:00.5679990

---------------------- Done ----------------------

Build: 0 errors, 12 warnings

1 个答案:

答案 0 :(得分:1)

如果SplashActivity启动但之后崩溃,我建议你注释掉以下内容。

在OnCreate的MainActivity上缩小问题范围:

  • UserDialogs.Init(本);
  • SetXLabsInitialization();

可能是其中一个需要不存在的程序集。

如果这些初始化没有破坏它,那么在Xamarin诊断输出日志中查找Xaml错误。