airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.83k stars 500 forks source link

App crashes on Mocks Load #574

Closed renclav closed 2 years ago

renclav commented 3 years ago

Using: def mvrx_version = "2.3.0" implementation "com.airbnb.android:mavericks:$mvrx_version" implementation "com.airbnb.android:mavericks-mocking:$mvrx_version" implementation "com.airbnb.android:mavericks-navigation:$mvrx_version" implementation "com.airbnb.android:mavericks-launcher:$mvrx_version"

When launching MavericksLauncherActivity via MavericksLauncherActivity.show(context) the app crashes with the following error:

java.lang.VerifyError: Superclass com.google.android.gms.common.internal.zze of com.google.android.gms.ads.internal.cache.zzc is declared final (declaration of 'com.google.android.gms.ads.internal.cache.zzc' appears in /data/app/~~_XFJEh1IlVkw-b2N6WaM5Q==/culturetrip.com.devrelease-1IXeGIEX8h66XIxoalBUOg==/base.apk!classes22.dex)
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.airbnb.mvrx.launcher.MavericksGlobalMockLibraryKt.getAsMavericksView(MavericksGlobalMockLibrary.kt:125)
        at com.airbnb.mvrx.launcher.MavericksGlobalMockLibraryKt.access$getAsMavericksView(MavericksGlobalMockLibrary.kt:1)
        at com.airbnb.mvrx.launcher.MavericksGlobalMockLibrary$mockableViewsFlow$2$1.invokeSuspend(MavericksGlobalMockLibrary.kt:62)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

The issue seems to be that the method getAsMavericksView inside MavericksGlobalMockLibrary.kt only catches ClassNotFoundException exceptions. While I recognise the possibility that this is not related to mavericks, I do think the error handling can be updated with no deviation to the existing library's logic.

elihart commented 3 years ago

should be simple enough to add a catch for VerifyError too, and any other exception type you can think would be good

renclav commented 3 years ago

@elihart I'm not sure what else, to be honest. Quite frankly, I'm still surprised the above can be thrown, I mean, how does it even compile? Could be incompatible interdependent libraries? This might be a one-off, probably best to not overload that catch block any more than necessary, so let's stop at two :) (The maverick in me says, "why not catch em all, it's not like the error is ever relevant to the consumer?")

elihart commented 3 years ago

Sounds good - interested in making the commit? We'll probably be making a new release soon