在调用RegisterNavigationServiceAppStart期间,我得到异常:MvvmCross.Platform.Exceptions.MvxIoCResolveException:找不到类型MvvmCross.Core.ViewModels.MvxNavigationServiceAppStart的构造函数失败在调试期间一切正常。但是当我构建版本并准备一个apk时,我得到了这个例外。下面我从设备监视器粘贴日志:
03-01 14:10:49.667:E / mono(21855):未处理异常:03-01 14:10:49.667:E / mono(21855):MvvmCross.Platform.Exceptions.MvxIoCResolveException:找不到类型MvvmCross的构造函数.Core.ViewModels.MvxNavigationServiceAppStart`1 [[AppMMobile.DataService.ViewModels.MainViewModel,AppMMobile.DataService,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]] 03-01 14:10:49.667:E / mono( 21855):在MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type type)[0x0002b] in:0 03-01 14:10:49.667:E / mono(21855):at MvvmCross.Platform.Mvx.IocConstruct [ T]()[0x00006] in:0 03-01 14:10:49.667:E / mono(21855):在MvvmCross.Platform.Mvx.ConstructAndRegisterSingleton [TInterface,TType]()[0x00006] in:0 03-01 14:10:49.667:E / mono(21855):在MvvmCross.Core.ViewModels.MvxApplication.RegisterNavigationServiceAppStart [TViewModel]()[0x00000] in <593dd944ead4429db9881ce186989310>:0 03-01 14:10:49.667:E / mono( 21855):在MappMMobile.DataService.App.Initialize()[0x0001a]中:0 03 -01 14:10:49.667:E / mono(21855):在<593dd944ead4429db9881ce186989310中的MvvmCross.Core.Platform.MvxSetup.InitializeApp(MvvmCross.Platform.Plugins.IMvxPluginManager pluginManager,MvvmCross.Core.ViewModels.IMvxApplication app)[0x00007] >:0 03-01 14:10:49.667:E / mono(21855):在<593dd944ead4429db9881ce186989310>中的MvvmCross.Core.Platform.MvxSetup.InitializeSecondary()[0x000b4]:0 03-01 14:10:49.667:E / mono(21855):在MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.b__7_0(System.Object被忽略)[0x00000] in <9d2864708eca4fb99992263d063bbc38>:0 03-01 14:10:49.667:E / mono(21855):at System。 Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object state)[0x00007] in:0 03-01 14:10:49.667:E / mono(21855):at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System .Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00071] in:0 03-01 14:10:49.667:E / mono(21855):at System.Threading.Ex ecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00000] in:0 03-01 14:10:49.667:E / mono(21855):在System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()[0x00021] in:0 03-01 14:10:49.667:E / mono(21855):at System.Threading.ThreadPoolWorkQueue.Dispatch()[0x00074 ] in:0 03-01 14:10:49.667:E / mono(21855):在System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()[0x00000] in:0
public class App : MvvmCross.Core.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
RegisterNavigationServiceAppStart<ViewModels.MainViewModel>();
[Registering my types...]
}
}
你能告诉我我做错了什么吗?
确保你的android项目中有一个文件LinkerPleaseInclude.cs
与this content:
using System;
using System.Collections.Specialized;
using System.Windows.Input;
using Android.App;
using Android.Views;
using Android.Widget;
using MvvmCross.Binding.BindingContext;
using MvvmCross.Core.Navigation;
using MvvmCross.Core.ViewModels;
namespace MyNamespace
{
// This class is never actually executed, but when Xamarin linking is enabled it does how to ensure types and properties
// are preserved in the deployed app
public class LinkerPleaseInclude
{
public void Include(Button button)
{
button.Click += (s,e) => button.Text = button.Text + "";
}
public void Include(CheckBox checkBox)
{
checkBox.CheckedChange += (sender, args) => checkBox.Checked = !checkBox.Checked;
}
public void Include(Switch @switch)
{
@switch.CheckedChange += (sender, args) => @switch.Checked = [email protected];
}
public void Include(View view)
{
view.Click += (s, e) => view.ContentDescription = view.ContentDescription + "";
}
public void Include(TextView text)
{
text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
text.Hint = "" + text.Hint;
}
public void Include(CheckedTextView text)
{
text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
text.Hint = "" + text.Hint;
}
public void Include(CompoundButton cb)
{
cb.CheckedChange += (sender, args) => cb.Checked = !cb.Checked;
}
public void Include(SeekBar sb)
{
sb.ProgressChanged += (sender, args) => sb.Progress = sb.Progress + 1;
}
public void Include(RadioGroup radioGroup)
{
radioGroup.CheckedChange += (sender, args) => radioGroup.Check(args.CheckedId);
}
public void Include(RadioButton radioButton)
{
radioButton.CheckedChange += (sender, args) => radioButton.Checked = args.IsChecked;
}
public void Include(RatingBar ratingBar)
{
ratingBar.RatingBarChange += (sender, args) => ratingBar.Rating = 0 + ratingBar.Rating;
}
public void Include(Activity act)
{
act.Title = act.Title + "";
}
public void Include(INotifyCollectionChanged changed)
{
changed.CollectionChanged += (s,e) => { var test = $"{e.Action}{e.NewItems}{e.NewStartingIndex}{e.OldItems}{e.OldStartingIndex}"; };
}
public void Include(ICommand command)
{
command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
}
public void Include(MvvmCross.Platform.IoC.MvxPropertyInjector injector)
{
injector = new MvvmCross.Platform.IoC.MvxPropertyInjector ();
}
public void Include(System.ComponentModel.INotifyPropertyChanged changed)
{
changed.PropertyChanged += (sender, e) => {
var test = e.PropertyName;
};
}
public void Include(MvxTaskBasedBindingContext context)
{
context.Dispose();
var context2 = new MvxTaskBasedBindingContext();
context2.Dispose();
}
public void Include(MvxNavigationService service, IMvxViewModelLoader loader)
{
service = new MvxNavigationService(null, loader);
}
public void Include(ConsoleColor color)
{
Console.Write("");
Console.WriteLine("");
color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Magenta;
Console.ForegroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.DarkGray;
}
}
}
它将确保链接器不会剥离MvvmCross工作所需的类,属性等。这就是可能发生的事情
HIH