问题
I created Setup : MvxAndroidSetup
public class Setup : MvxAndroidSetup
{
public Setup(Context applicationContext)
: base(applicationContext)
{
}
protected override IMvxApplication CreateApp()
{
return new App();
}
protected override IEnumerable<Assembly> AndroidViewAssemblies =>
new List<Assembly>(base.AndroidViewAssemblies)
{
typeof(Android.Support.Design.Widget.NavigationView).Assembly,
typeof(Android.Support.Design.Widget.FloatingActionButton).Assembly,
typeof(Android.Support.V7.Widget.Toolbar).Assembly,
typeof(Android.Support.V4.Widget.DrawerLayout).Assembly,
typeof(Android.Support.V4.View.ViewPager).Assembly,
typeof(MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView).Assembly
};
/// <summary>
/// This is very important to override. The default view presenter does not know how to show fragments!
/// </summary>
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
return mvxFragmentsPresenter;
}
}
I using mvvmscross Version 5.2.1 I have issue in line code var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);. when run project Visual studio 2017 in mac notify that:
System.MissingMethodException: Method 'MvvmCross.Droid.Views.MvxAndroidViewPresenter..ctor' not found.
at VietOrder.Droid.Setup.CreateViewPresenter () [0x00001] in /Volumes/Data/Dev/VietOrder/Xamarin/VietOrder/VietOrder.Droid/Setup.cs:46
at MvvmCross.Droid.Platform.MvxAndroidSetup.CreateViewDispatcher () [0x00000] in C:\projects\mvvmcross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetup.cs:124
at MvvmCross.Core.Platform.MvxSetup.InitializeViewDispatcher () [0x00000] in C:\projects\mvvmcross\MvvmCross\Core\Core\Platform\MvxSetup.cs:260
at MvvmCross.Core.Platform.MvxSetup.InitializeSecondary () [0x000f8] in C:\projects\mvvmcross\MvvmCross\Core\Core\Platform\MvxSetup.cs:91
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__7_0 (System.Object ignored) [0x00000] in C:\projects\mvvmcross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetupSingleton.cs:92
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
Thanks!
回答1:
I think I solved it but its been at the tail end of a long journey to upgrade to the latest MvvmCross version (5.3.1) from version 4.4.0. I will identify the steps I needed to go through the upgrade. It should be noted that prior to this I have updated all Xamarin and other packages to the latest and greatest and ensured the project compiles and runs. In addition I updated Xamarin itself to 4.7.10.22 which brought support for Android 8.0 (I don't have an iOS front-end yet). Here the steps I went through to update to MvvmCross 5.3.1:
- Upgrade all MvvmCross packages to 5.3.1
- Remove MvvmCross.Droid.Shared (4.4.0)
- Add MvvmCross.Droid.Support.Core.UI (5.3.1)
- Add MvvmCross.Droid.Support.Core.Utils (5.3.1)
- Add MvvmCross.Droid.Support.Fragment (5.3.1)
Now to answer your questions, I changed my Setup class to subclass from MvxAppCompatSetup. Call to the MvxAppCompatSetup changed to a simple creation of a new MvxAppCompatViewPresenter() (see below) plus removal of import of MvvmCross.Droid.Shared.Presenter:
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
return new MvxAppCompatViewPresenter(AndroidViewAssemblies);
}
In addition, since I was using some Fragments, I needed to change the Attributes on them from MvxFragment to MvxFragmentPresentation. Last change was to change my main Activity from sub-classing MvxCachingFragmentCompatActivity to sub-classing MvxAppCompatActivity. All this did the trick for me and hopefully will help you.
P.S. I still have to change navigation to conform to the new NavigationService.
来源:https://stackoverflow.com/questions/46802330/system-missingmethodexception-method-mvvmcross-droid-views-mvxandroidviewprese