使用源代码

时间:2017-02-10 17:18:47

标签: c# android xamarin xamarin.android 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类型参数名称:元素at   Xamarin.Forms.Platform.Android.VisualElementRenderer`1 [TElement] .Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement   (Xamarin.Forms.VisualElement元素)[0x00011] in   F:\工作空间\ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ VisualElementRenderer.cs:139   在Xamarin.Forms.Platform.Android.Platform.CreateRenderer   (Xamarin.Forms.VisualElement元素)[0x00022] in   F:\工作区\ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:289   在Xamarin.Forms.Platform.Android.Platform.AddChild   (Xamarin.Forms.VisualElement视图,System.Boolean布局)[0x0001d] in   F:\工作区\ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:530   在Xamarin.Forms.Platform.Android.Platform.SetPage(Xamarin.Forms.Page   newRoot)[0x000a2] in   F:\工作空间\ Xamarin.Forms \ Xamarin.Forms.Platform.Android \ Platform.cs:414   在Xamarin.Forms.Platform.Android.FormsApplicationActivity.Inte at   md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.n_onCreate(母语   方法)at   md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.onCreate(MvxFormsApplicationActivity.java:31)     在android.app.Activity.performCreate(Activity.java:5231)at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)     在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)     在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)     在android.app.ActivityThread.access $ 800(ActivityThread.java:135)     在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)     在android.os.Handler.dispatchMessage(Handler.java:102)at   android.os.Looper.loop(Looper.java:136)at   android.app.ActivityThread.main(ActivityThread.java:5001)at   java.lang.reflect.Method.invokeNative(Native Method)at   java.lang.reflect.Method.invoke(Method.java:515)at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)at   dalvik.system.NativeStart.main(原生方法)

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

1 个答案:

答案 0 :(得分:1)

我终于想出了如何运行我的应用程序。我发现,在 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

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