Xamarin.Forms MissingMethodException: 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' 未找到

Xamarin.Forms MissingMethodException: 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found

我关注了以下 link 中的所有内容: https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/ 我写的代码可以在这里找到:http://github.com/foyzulkarim/XamarinFormsDrawer 我使用 UWP 项目在我的 Windows 10 本地计算机中成功部署了相同的项目,但是每当我想在模拟器或我的设备中部署时,它都会抛出以下异常。

System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:33.636 D/Mono    (10472): DllImport attempting to load: '/system/lib/liblog.so'.
09-17 17:16:33.637 D/Mono    (10472): DllImport loaded library '/system/lib/liblog.so'.
09-17 17:16:33.637 D/Mono    (10472): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
09-17 17:16:33.637 D/Mono    (10472): Searching for '__android_log_print'.
09-17 17:16:33.637 D/Mono    (10472): Probing '__android_log_print'.
09-17 17:16:33.637 D/Mono    (10472): Found as '__android_log_print'.
09-17 17:16:33.645 I/MonoDroid(10472): UNHANDLED EXCEPTION:
09-17 17:16:33.658 I/MonoDroid(10472): System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:282 
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\RendererFactory.cs:10 
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00015] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:248 
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00089] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:237 
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0009b] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:336 
09-17 17:16:33.658 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:410 
09-17 17:16:33.659 I/MonoDroid(10472):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x00158] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:123 
09-17 17:16:33.659 I/MonoDroid(10472):   at App1.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00018] in C:\Users\foyzu\Source\Github\XamarinForms\XamarinFormsDrawer\App1\App1\App1.Droid\MainActivity.cs:23 
09-17 17:16:33.659 I/MonoDroid(10472):   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <71c3e52f1b484794bca1cdfb1b8b1fdb>:0 
09-17 17:16:33.659 I/MonoDroid(10472):   at (wrapper dynamic-method) System.Object:1a87dfa6-a154-49b0-925d-8ddad74d97cf (intptr,intptr,intptr)
09-17 17:16:33.677 W/art     (10472): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
09-17 17:16:33.681 D/Mono    (10472): DllImport searching in: '__Internal' ('(null)').
09-17 17:16:33.681 D/Mono    (10472): Searching for 'java_interop_jnienv_throw'.
09-17 17:16:33.681 D/Mono    (10472): Probing 'java_interop_jnienv_throw'.
09-17 17:16:33.681 D/Mono    (10472): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.

09-17 17:16:34.399 E/mono    (10472): 
09-17 17:16:34.399 E/mono    (10472): Unhandled Exception:
09-17 17:16:34.399 E/mono    (10472): System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:34.399 E/mono-rt (10472): [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1

解决方案是,我需要更新包,只有 Xamarin.Forms 包。就像下图一样。

更新后,packages.config 文件应该如下所示

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Forms" version="2.3.2.127" targetFramework="monoandroid60" />
</packages>

并忽略下面的其余包。

更新 Xamarin.Forms nuget 包对我不起作用。就我而言,需要更新 Android Studio 才能使 Xamarin.Forms 与 Visual Studio 一起工作。更新后,重新启动 Android Studio 并再次查找更新并在找到时应用它们。您需要不断重复此操作,因为并非所有更新都会一次性安装。至少这是我的情况。

我想这行得通,因为 Android Studio 包含 Android SDK 或 Visual Studio 或 Xamarin 需要的一些其他组件。

只需将您的 nuget-packages 更新到最新版本(Xamarin.forms 也是)

清洁溶液

关闭visualstudio

删除以下所有 .zip 文件:

C:\Users[你用户名]\AppData\Local\Xamarin\zips

重新启动 visualstudio 并重新编译 :) 它将再次下载那些 .zip 文件(可能需要几分钟)。这些 zip 包括相关的 android 支持库。所以它会下载真实的(你引用的 xamarin.forms 版本相关)。

大部分情况需要更新Xamarin.Forms包到最新版本

on all your projects( To avoid Other Exceptions)

对于便携式、.Driod、.IOSWindows Phone 如果存在,则必须清理您的解决方案并关闭 visual studio 并再次打开它,Finlay 一切都会好起来的。

但在某些情况下,您需要将 Xamarin.Forms 软件包降级为 2.3,而不是 2.5.0.121934