Java.Lang.ClassNotFoundException:没有找到类“com.google.android.gms.vision.text.TextRecognizer $ Builder”Xamarin Android

问题描述 投票:1回答:2

在Xamarin Android的下面一行获取Java.Lang.ClassNotFoundException错误

TextRecognizer textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();

{Java.Lang.ClassNotFoundException: Didn't find class "com.google.android.gms.vision.text.TextRecognizer$Builder" on path: DexPathList[[zip file "/data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/base.apk"],nativeLibraryDirectories=[/data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/lib/x86, /data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/base.apk!/lib/x86, /system/lib]]
      at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00114] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Java.Interop.JniType..ctor (System.String classname) [0x00006] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Java.Interop.JniType.GetCachedJniType (Java.Interop.JniType& cachedType, System.String classname) [0x00018] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Java.Interop.JniPeerMembers.get_JniPeerType () [0x0000c] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Java.Interop.JniPeerMembers+JniInstanceMethods.get_JniPeerType () [0x0000a] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Java.Interop.JniPeerMembers+JniInstanceMethods.StartCreateInstance (System.String constructorSignature, System.Type declaringType, Java.Interop.JniArgumentValue* parameters) [0x0003f] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 
      at Android.Gms.Vision.Texts.TextRecognizer+Builder..ctor (Android.Content.Context context) [0x0005b] in <3d29e02cc4534fbf8547810969e46514>:0 
      at dine.MainActivity.Ocr (Android.Graphics.Bitmap bitmap) [0x00001] in D:\dine\dine\MainActivity.cs:753 
      at dine.MainActivity.StartCapture () [0x001ad] in D:\dine\dine\MainActivity.cs:711 
      --- End of managed Java.Lang.ClassNotFoundException stack trace ---
    java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.vision.text.TextRecognizer$Builder" on path: DexPathList[[zip file "/data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/base.apk"],nativeLibraryDirectories=[/data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/lib/x86, /data/app/dine.dine-4Lcxwvl8j7kQmp8qGBPDCA==/base.apk!/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    }
android xamarin xamarin.android google-play-services vision
2个回答
0
投票

如果已启用proguard,请在项目的proguard.cfg文件中添加以下内容:

# Google GMS
-keep public class com.google.android.gms.* { public *; }
-keep class com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver
-dontwarn com.google.android.gms.**

这将在编译时保留所提及的类,从而在运行时可用。

编辑

在项目设置中启用Proguard时,需要在项目中添加*.cfgfile,即。 proguard.cfgmypg.cfg

然后右键单击新文件 - >选择Properties然后设置:

  • Build ActionProguardConfiguration
  • Copy to Output DirectoryDo not copy

最后将您的proguard行添加到此文件中。每一行都是一个单独的设置

Aaditi

添加GMS TextRecognizer部分,看它是否有效?

# Google GMS
-keep public class com.google.android.gms.* { public *; }
-keep class com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver
-dontwarn com.google.android.gms.**

# GMS TextRecognizer
-keep public class com.google.android.gms.vision.text.TextRecognizer { public *; }
-keep public class com.google.android.gms.vision.text.TextRecognizer.** { public *; }
-keep class com.google.android.gms.vision.text.TextRecognizer
-keep class com.google.android.gms.vision.text.TextRecognizer.**

0
投票

问题是我正在使用导致问题的预览版软件包,我将预览版包装更改为稳定版本,即Xamarin.GooglePlayServices.Vision 71.1502.0-preview1Xamarin.GooglePlayServices.Vision 60.1142.1,现在没有更多例外。

© www.soinside.com 2019 - 2024. All rights reserved.