1
votes

I'm binding a kotlin library to xamarin android, and after binding and resolving all the errors, I get an unexpected error with no explanation or cause for the exception,

Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/viewbinding/ViewBinding;'

Here is the stacktrace I get:

MainActivity.cs:40 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <4ccdb3137d974856b786e1aeebbfbab6>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr) --- End of managed Java.Lang.NoClassDefFoundError stack trace --- java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/viewbinding/ViewBinding; at crc6473617f77d52b50b9.MainActivity.n_onCreate(Native Method) at crc6473617f77d52b50b9.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 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:1808) at android.os.Handler.dispatchMessage(Handler.java:106) 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) Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.viewbinding.ViewBinding" on path: DexPathList[[zip file "/data/app/com.companyname.stripepaymentdemo-oGbK81Ux2TUQ5Jelqfi7GQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.stripepaymentdemo-oGbK81Ux2TUQ5Jelqfi7GQ==/lib/x86, /data/app/com.companyname.stripepaymentdemo-oGbK81Ux2TUQ5Jelqfi7GQ==/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)

I've looked online for similar xamarin android issues I'm yet to find one Please can someone help ?

1
The most likely reason for this error is that a mandatory Java library needs to be added to the application project (.csproj) , check docs.microsoft.com/en-us/xamarin/android/platform/…. - ColeX - MSFT
Thanks, Please do you have any idea about how to detect which class exactly is missing ? - John Code
The error shows it seems related to AndroidX library. - ColeX - MSFT

1 Answers

0
votes

Based on the answer found here, (credit to https://github.com/AlexanderMelchers) we followed these steps and were able to get the Stripe Android SDK (which depends on AndroidX) working in Xamarin Forms:

  1. Download the AndroidX.Core library and its dependencies from the Maven-repository.
  2. Create a new directory and unpack all downloaded JAR-files into that directory.
  3. Open the AAR-files with an archiver-tool, extract their classes.jar-files, and place the contents of the latter in the above directory as well.
  4. Run "jar cvf androidx.jar ." within the aforementioned directory to package all AndroidX-files together in a new JAR.
  5. Add this JAR to your Android binding-project as an embedded reference JAR.
  6. Add your binding to an Android App project, and try to build it. You'll probably get some build errors related to duplicate class inclusions. Remove these files from the directory created in 2 and repeat steps 4 & 5 until there are no such errors left.
  7. Create/build your NuGet. You should now be able to successfully run the code contained in the partner SDK.