简体   繁体   English

Xamarin Forms, Android - Java.Lang.ClassNotFoundException

[英]Xamarin Forms, Android - Java.Lang.ClassNotFoundException

I'm currently updating a Xamarin Forms App and suddenly experiencing this error on Android:我目前正在更新 Xamarin Forms 应用程序,突然在 Android 上遇到此错误:

Exception   {Java.Lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GooglePlayServicesUtil" on path: DexPathList[[zip file "/data/app/com.alphacoreconsulting.tflmetrosound-Ek3U1cNyzLe9Jayp9enzXQ==/base.apk"],nativeLibraryDirectories=[/data/app/c…} Java.Lang.ClassNotFoundException

It triggers on this line:它在这一行触发:

Xamarin.FormsMaps.Init(this, bundle);

I've researched and I've ensured all packages are the same version:我已经研究并确保所有软件包都是相同的版本:

在此处输入图像描述

Please would anyone be able to offer some help on this?请问有人可以提供一些帮助吗?

UPDATE:更新:

I have since updated the proguard.cfg file and added this line:我已经更新了 proguard.cfg 文件并添加了这一行:

-keep public class com.google.android.gms.common.GooglePlayServicesUtil

After adding this I am now experiencing this error:添加后,我现在遇到此错误:

no static method "Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable(Landroid/content/Context;)I"

You will see this exception at runtime when code has been stripped from the executable usually by the linker or R8/Proguard.当代码通常被 linker 或 R8/Proguard 从可执行文件中剥离时,您将在运行时看到此异常。 You can provide a configuration file to both tools allowing you to keep code the linker or R8/Proguard think you are not using.您可以为这两种工具提供一个配置文件,使您可以保留 linker 或 R8/Proguard 认为您没有使用的代码。 These tools are not able to properly detect code you use at runtime via reflection for example.例如,这些工具无法通过反射正确检测您在运行时使用的代码。

Here is the documentation for the linker configuration file.这是 linker 配置文件的文档 Another approach is to use a "LinkerPleaseInclude.cs" file manually referencing the code you do not want to be linked out.另一种方法是使用“LinkerPleaseInclude.cs”文件手动引用您不想链接出去的代码。

Here is the documentation for the R8/Proguard configuration file.这是 R8/Proguard 配置文件的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM