xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

Java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.AlertDialogLayout" #206

Closed AnthonyLatty closed 5 years ago

AnthonyLatty commented 5 years ago

Xamarin.Android Version (eg: 6.0):

9.0

Operating System & Version (eg: Mac OSX 10.11):

Mac OS 10.14.6

Support Libraries Version (eg: 23.3.0):

Upgraded from 28.0.0.1 to 28.0.0.3

Describe your Issue:

When using latest Xamarin.Android with support libraries 28.0.0.3 there is crash in "AlertDialogLayout" (strack trace below).

java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.AlertDialogLayout" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar"

Steps to Reproduce (with link to sample solution if possible):

Update Visual Studio to latest stable. Add project targeting API Level 28. Add latest support libraries 28.0.0.3. Create a Dialog Run App.

Include any relevant Exception Stack traces, build logs, adb logs:

dalvik.system.BaseDexClassLoader.findClass BaseDexClassLoader.java:134
java.lang.ClassLoader.loadClass ClassLoader.java:379
java.lang.ClassLoader.loadClass ClassLoader.java:312
android.view.LayoutInflater.createView LayoutInflater.java:606
android.view.LayoutInflater.createViewFromTag LayoutInflater.java:790
android.view.LayoutInflater.createViewFromTag LayoutInflater.java:730
android.view.LayoutInflater.inflate LayoutInflater.java:492
android.view.LayoutInflater.inflate LayoutInflater.java:423
android.view.LayoutInflater.inflate LayoutInflater.java:374
android.support.v7.app.AppCompatDelegateImpl.setContentView
android.support.v7.app.AppCompatDialog.setContentView
android.support.v7.app.AlertController.installContent
android.support.v7.app.AlertDialog.onCreate
android.app.Dialog.dispatchOnCreate Dialog.java:407
android.app.Dialog.show Dialog.java:302
android.support.v4.app.DialogFragment.onStart
android.support.v4.app.Fragment.performStart
android.support.v4.app.FragmentManagerImpl.moveToState
android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState
android.support.v4.app.FragmentManagerImpl.moveToState
android.support.v4.app.BackStackRecord.executeOps
android.support.v4.app.FragmentManagerImpl.executeOps
android.support.v4.app.FragmentManagerImpl.executeOpsTogether
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute
android.support.v4.app.FragmentManagerImpl.execPendingActions
android.support.v4.app.FragmentManagerImpl$1.run
android.os.Handler.handleCallback Handler.java:873
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:193
android.app.ActivityThread.main ActivityThread.java:6718
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:493
com.android.internal.os.ZygoteInit.main ZygoteInit.java:858
heromcp commented 5 years ago

I have the same problem with Xamarin.Forms on release version.

FATAL EXCEPTION: main Process: com.xxxxxxxx.movil, PID: 4377 android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class android.support.v7.widget.AlertDialogLayout

Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class android.support.v7.widget.AlertDialogLayout

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.AlertDialogLayout" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.phuyusalud.movil-MNIzraJSi4xxl05wRbOE5g==/base.apk"],nativeLibraryDirectories=[/data/app/com.phuyusalud.movil-MNIzraJSi4xxl05wRbOE5g==/lib/arm64, /system/fake-libs64, /data/app/com.phuyusalud.movil-MNIzraJSi4xxl05wRbOE5g==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]

Redth commented 5 years ago

Are you using proguard/r8 and/or multidex?

You may need to add some rules to proguard/r8 to keep these classes if so

-keep android.support.v7.widget.AlertDialogLayout
AnthonyLatty commented 5 years ago

Where would you specify these rules for r8??

StevenGranados commented 5 years ago

Anyone encountering this issue, the line that worked for me was -keep public class android.support.v7.widget.*

mwerickson commented 4 years ago

@StevenGranados I'm running into the same issue, where do you specify that rule?

StevenGranados commented 4 years ago

Proguardhelp Create a file with the line in it and set the build action of the file to proguard configuration.

mwerickson commented 4 years ago

Thanks Steven! So, I'm guessing R8 also reads this config file?

StevenGranados commented 4 years ago

It works for me with r8 so I guess it does.

swapnil591 commented 4 years ago

Getting error after adding proguard.cfg Screenshot 2019-12-31 at 2 02 55 PM

swapnil591 commented 4 years ago

Getting error after adding proguard.cfg Screenshot 2019-12-31 at 2 02 55 PM

Solved Make sure proguard.cfg file encoding is UTF-8

eclipsed4utoo commented 4 years ago

And if it's not obvious(like it wasn't to me when I added the file), also make sure you set the BuildAction to ProguardConfiguration.

image

StevenGranados commented 4 years ago

xamarin/Xamarin.Forms#9318 Might help with this issue in Forms 4.5.0