dotnet / android-libraries

.NET for Android bindings for Google's libraries, such as AndroidX, GooglePlayServices, Firebase, and MLKit and their 3rd party dependency libraries.
MIT License
230 stars 48 forks source link

Runtime Crash java.lang.ClassNotFoundException: Didn't find class "androidx.security.crypto.MasterKey$Builder" #402

Closed myworkpage closed 3 years ago

myworkpage commented 3 years ago

Version Information

Describe your Issue:

I trying to convert an Android Native library to Xamarin.Android binding project, the native library contains the AndroidX libraries in the AndroidX.Security.Crypto namespace I couldn't find the MasterKey class where we have only MasterKeys which got deprecated. When I try to run the application it throws the below runtime error and application is getting crashed on Launch.

MicrosoftTeams-image

Below is the error causing Runtime crash:

FATAL EXCEPTION: CoreSDKHandlerThread-7396e67d-94f0-4e37-81eb-c80e26e136db [AndroidRuntime] Process: com.sample.app, PID: 20143 [AndroidRuntime] java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/security/crypto/MasterKey$Builder; [AndroidRuntime] at com.emarsys.core.storage.SecureSharedPreferencesProvider.createMasterKey(SecureSharedPreferencesProvider.kt:61) [AndroidRuntime] at com.emarsys.core.storage.SecureSharedPreferencesProvider.(SecureSharedPreferencesProvider.kt:24) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent$sharedPreferences$2.invoke(DefaultEmarsysComponent.kt:335) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent$sharedPreferences$2.invoke(DefaultEmarsysComponent.kt:330) [AndroidRuntime] at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent.getSharedPreferences(DefaultEmarsysComponent.kt:330) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent$keyValueStore$2.invoke(DefaultEmarsysComponent.kt:779) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent$keyValueStore$2.invoke(DefaultEmarsysComponent.kt:778) [AndroidRuntime] at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent.getKeyValueStore(DefaultEmarsysComponent.kt:778) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysComponent.initializeResponseHandlers(DefaultEmarsysComponent.kt:264) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysDependencies.init$lambda-0(DefaultEmarsysDependencies.kt:15) [AndroidRuntime] at com.emarsys.di.DefaultEmarsysDependencies.lambda$sZ1g4MKyXk-ksdRnf8h9mc0w90Q(Unknown Source:0) [AndroidRuntime] at com.emarsys.di.-$$Lambda$DefaultEmarsysDependencies$sZ1g4MKyXk-ksdRnf8h9mc0w90Q.run(Unknown Source:4) [AndroidRuntime] at android.os.Handler.handleCallback(Handler.java:938) [AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:99) [AndroidRuntime] at com.emarsys.core.concurrency.CoreHandler.dispatchMessage(CoreHandler.kt:13) [AndroidRuntime] at android.os.Looper.loop(Looper.java:223) [AndroidRuntime] at android.os.HandlerThread.run(HandlerThread.java:67) [AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.security.crypto.MasterKey$Builder" on path: DexPathList[[zip file "/data/app/aBGH0YmDrD_5YPSQqluxpw==/com.sample.app-qETjbPXm8wZT1TENQqdHaQ==/base.apk"],nativeLibraryDirectories=[/data/app/aBGH0YmDrD_5YPSQqluxpw==/com.sample.app-qETjbPXm8wZT1TENQqdHaQ==/lib/arm64, /data/app/~~aBGH0YmDrD_5YPSQqluxpw==/com.sample.app-qETjbPXm8wZT1TENQqdHaQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]] [AndroidRuntime] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:379) [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:312) [AndroidRuntime] ... 19 more

jpobst commented 3 years ago

It looks like the MasterKey class is only available in alpha versions of 1.1.0.

As a policy, we only bind stable versions of AndroidX. You will need to either wait for Google to make it stable (which will automatically trigger our system to bind it) or create your own binding of the alpha version.

https://maven.google.com/web/index.html?q=crypto#androidx.security:security-crypto

jpobst commented 3 years ago

Or if you just need the Java code to exist, you could probably download the alpha aar, pull the classes.jar file out of it, and add it to your project as an <EmbeddedJar>.

jpobst commented 3 years ago

Due to demand (including a MS partner team), we have published a "preview" NuGet of 1.1.0-alpha03: https://www.nuget.org/packages/Xamarin.AndroidX.Security.SecurityCrypto/1.1.0-alpha03

Hopefully this helps you out!

Note there is no guarantee that this will updated with future pre-release builds, but will definitely be updated when 1.1.0 stable is published by Google.