BlinkID / blinkid-xamarin

ID scanning SDK, wrapped for cross-platform apps built with Xamarin.
https://microblink.com/blinkid
50 stars 24 forks source link

Cannot instantiate BlinkIdActivity when R8 enabled #42

Closed AdenITD closed 4 years ago

AdenITD commented 4 years ago

Repo steps:

  1. Download the Sample App, and open the Forms sln.
  2. In the Forms Android app, open the Android Build properties, change the Code Shrinker to ProGuard, then run the app and validate that again you can initiate a scan.
  3. Go back into Android Build properties and change the Code Shrinker option to R8.
  4. Run the app and try to initiate a scan.
  5. Observe that the app crashes @ microblinkFactory.CreateMicroblinkScanner()

Exception: Java.Lang.ClassNotFoundException

Message:

Didn't find class "com.microblink.MicroblinkSDK" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/base.apk"],nativeLibraryDirectories=[/data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/lib/arm64, /system/fake-libs64, /data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/base.apk!/lib/arm64-v8a, /system/lib64]]

StackTrace:

  at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00119] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Java.Interop.JniType..ctor (System.String classname) [0x00006] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Java.Interop.JniType.GetCachedJniType (Java.Interop.JniType& cachedType, System.String classname) [0x00018] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Java.Interop.JniPeerMembers.get_JniPeerType () [0x0000c] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.GetMethodInfo (System.String encodedMember) [0x0002b] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeVoidMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00000] in <ce53014a5d7d49af8f964173870eeb58>:0 
  at Com.Microblink.MicroblinkSDK.SetShowTimeLimitedLicenseWarning (System.Boolean p0) [0x00018] in /Users/igrce/Awork/Xamarin/deploy-repos/github/blinkid-xamarin/Binding/Android/obj/Release/generated/src/Com.Microblink.MicroblinkSDK.cs:202 
  at Microblink.Forms.Droid.MicroblinkScannerImplementation..ctor (System.String licenseKey, System.String licensee, System.Boolean showTimeLimitedLicenseWarning, Microblink.Forms.Droid.IMicroblinkScannerAndroidHostActivity androidHostActivity) [0x0000e] in /Users/igrce/Awork/Xamarin/deploy-repos/github/blinkid-xamarin/Binding/Forms/BlinkID.Forms/BlinkID.Forms.Android/MicroblinkScannerImplementation.cs:52 
  at Microblink.Forms.Droid.MicroblinkScannerFactoryImplementation.CreateMicroblinkScanner (System.String licenseKey, System.Boolean showTimeLimitedLicenseWarning) [0x00012] in /Users/igrce/Awork/Xamarin/deploy-repos/github/blinkid-xamarin/Binding/Forms/BlinkID.Forms/BlinkID.Forms.Android/MicroblinkScannerImplementation.cs:105 
  at BlinkIDApp.BlinkIDPage..ctor () [0x0003b] in /Users/adenearnshaw/Downloads/blinkid-xamarin-master/Samples/Forms/Core/BlinkIDPage.xaml.cs:59 
  at BlinkIDApp.App..ctor () [0x00008] in /Users/adenearnshaw/Downloads/blinkid-xamarin-master/Samples/Forms/Core/Core.cs:12 
  at BlinkIDApp.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00020] in /Users/adenearnshaw/Downloads/blinkid-xamarin-master/Samples/Forms/Droid/MainActivity.cs:45 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <f136c45b4a184119b54f2647ad4225f6>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)
  --- End of managed Java.Lang.ClassNotFoundException stack trace ---
java.lang.ClassNotFoundException: Didn't find class "com.microblink.MicroblinkSDK" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/base.apk"],nativeLibraryDirectories=[/data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/lib/arm64, /system/fake-libs64, /data/app/com.microblink.xamarin.blinkid-VOC8UVICfS3fhIL8wNwxLA==/base.apk!/lib/arm64-v8a, /system/lib64]]
    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 crc6454688335eb7ecd6f.MainActivity.n_onCreate(Native Method)
    at crc6454688335eb7ecd6f.MainActivity.onCreate(:31)
    at android.app.Activity.performCreate(Activity.java:7323)
    at android.app.Activity.performCreate(Activity.java:7314)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2930)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3085)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6745)
    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)
i1E commented 4 years ago

Hi @AdenITD,

thank you for the issue report. We are investigating this and we will get back to you when we find a solution. It seems that while performing code shrinking, R8 removes some methods and classes from our SDK that should be present, which is not the case with the proguard.

Also, we have tested our native Android SDK with R8 and everything works fine, this problem is specific for Xamarin.

i1E commented 4 years ago

Hi @AdenITD,

for now, you should include custom shrinker configuration file, like described here and add the following rule:

-keep public class com.microblink.**
AdenITD commented 4 years ago

Thank's Ivan, adding the custom proguard config with the line above has worked.