使用源代码调试Xamarin Forms应用程序

我一直在使用Xamarin Forms和MVVMCross库开发我的应用程序,我遇到了一个错误,导致Xamarin.Forms . 我以为我会下载Xamarin Forms的源代码并进行调试 . 我已经克隆了git存储库,然后将这些项目添加到我的解决方案中:

  • Xamarin.Forms.Core

  • Xamarin.Forms.Maps

  • Xamarin.Forms.Maps.Android

  • Xamarin.Forms.Platform

  • Xamarin.Forms.Platform.Android

  • Xamarin.Forms.Platform.Android(货运代理)

  • Xamarin.Forms.Platform.Android.FormsViewGroup

  • Xamarin.Forms.Xaml

我删除了这些库的NuGet引用并替换了我的项目中的引用 . 应用程序正在构建,此时一切正常,但当我将其部署到模拟器时,应用程序崩溃 . 这是stacktrace:

android.runtime.JavaProxyThrowable:System.ArgumentException:element的类型不是Xamarin.Forms.View参数名称:元素在Xamarin.Forms.Platform.Android.VisualElementRenderer`1 [TElement] .Xamarin.Forms.Platform.Android.IVisualElementRenderer F:\ workspace \ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ VisualElementRenderer.cs:139中的.SetElement(Xamarin.Forms.VisualElement元素)[0x00011],位于Xamarin.Forms.Platform.Android.Platform.CreateRenderer(Xamarin) .Forms.VisualElement元素)[0x00022]在F:\ workspace \ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:289 at Xamarin.Forms.Platform.Android.Platform.AddChild(Xamarin.Forms.VisualElement)视图,System.Boolean布局)[0x0001d]在F:\ workspace \ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:530中的Xamarin.Forms.Platform.Android.Platform.SetPage(Xamarin.Forms . 页面newRoot)[0x000a2]在F:\ workspace \ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:414在Xamarin.Forms.Platform.Android.FormsApplicationAc tivity.Inte在md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.n_onCreate(本机方法)在md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.onCreate(MvxFormsApplicationActivity.java:31)在android.app.Activity.performCreate(Activity.java:5231)在android.app.Instrumentation.callActivityOnCreate( Instrumentation.java:1087)android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148),android.app.A活动,活动传递活动(ActivityThread.java:2233),位于android.app.ActivityThread.access $ 800(ActivityThread.java: 135)在Android.app.Loper.loop(Looper.java:136)的android.app.Handler.dispatchMessage(Handler.java:102)上的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)处android.app.ActivityThread.main(ActivityThread.java:5001)位于com.android的java.lang.reflect.Method.invoke(Method.java:515)的java.lang.reflect.Method.invokeNative(Native Method)中 . internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)a t com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)at dalvik.system.NativeStart.main(Native Method)

它看起来像Xamarin找不到 NavigationPage 类的视图rednerer . 我正在使用Xamarin.Android 7.0和Java 8进行编译 .

回答(1)

3 years ago

我终于想出了如何运行我的应用程序 . 我发现,在Xamarin.Forms.Platform.Android命名空间的AssemblyInfo类中,我已经灰显了属性,这些属性告诉应用程序为视图注册渲染器 . 这就是我所说的:

#if ROOT_RENDERERS
[assembly: ExportRenderer (typeof (BoxView), typeof (BoxRenderer))]
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
[assembly: ExportRenderer (typeof (Editor), typeof (EditorRenderer))]
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
[assembly: ExportRenderer (typeof (Image), typeof (ImageRenderer))]
[assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))]
[assembly: ExportRenderer (typeof (TableView), typeof (TableViewRenderer))]
[assembly: ExportRenderer (typeof (ListView), typeof (ListViewRenderer))]
[assembly: ExportRenderer (typeof (Slider), typeof (SliderRenderer))]
[assembly: ExportRenderer (typeof (WebView), typeof (WebViewRenderer))]
[assembly: ExportRenderer (typeof (SearchBar), typeof (SearchBarRenderer))]
[assembly: ExportRenderer (typeof (Switch), typeof (SwitchRenderer))]
[assembly: ExportRenderer (typeof (DatePicker), typeof (DatePickerRenderer))]
[assembly: ExportRenderer (typeof (TimePicker), typeof (TimePickerRenderer))]
[assembly: ExportRenderer (typeof (Picker), typeof (PickerRenderer))]
[assembly: ExportRenderer (typeof (Stepper), typeof (StepperRenderer))]
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
[assembly: ExportRenderer (typeof (ScrollView), typeof (ScrollViewRenderer))]
[assembly: ExportRenderer (typeof (Toolbar), typeof (ToolbarRenderer))]
[assembly: ExportRenderer (typeof (ActivityIndicator), typeof (ActivityIndicatorRenderer))]
[assembly: ExportRenderer (typeof (Frame), typeof (FrameRenderer))]
[assembly: ExportRenderer (typeof (NavigationMenu), typeof (NavigationMenuRenderer))]
[assembly: ExportRenderer (typeof (OpenGLView), typeof (OpenGLViewRenderer))]

[assembly: ExportRenderer (typeof (TabbedPage), typeof (TabbedRenderer))]
[assembly: ExportRenderer (typeof (NavigationPage), typeof (NavigationRenderer))]
[assembly: ExportRenderer (typeof (CarouselPage), typeof (CarouselPageRenderer))]
[assembly: ExportRenderer (typeof (Page), typeof (PageRenderer))]
[assembly: ExportRenderer (typeof (MasterDetailPage), typeof (MasterDetailRenderer))]
#endif

当我评论这个编译条件时,一切顺利 .