在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)
}
如果已启用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时,需要在项目中添加*.cfg
file,即。 proguard.cfg
或mypg.cfg
然后右键单击新文件 - >选择Properties
然后设置:
Build Action
:ProguardConfiguration
Copy to Output Directory
:Do not copy
最后将您的proguard行添加到此文件中。每一行都是一个单独的设置
添加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.**
问题是我正在使用导致问题的预览版软件包,我将预览版包装更改为稳定版本,即Xamarin.GooglePlayServices.Vision
71.1502.0-preview1
到Xamarin.GooglePlayServices.Vision
60.1142.1
,现在没有更多例外。