coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.82k stars 662 forks source link

API 19 java.lang.VerifyError crash after updating to Coil 1.0.0 #591

Closed G00fY2 closed 3 years ago

G00fY2 commented 3 years ago

Hi,

thanks for this great library! So after some hours of debugging I finally came closer to the cause of crash reports we get in production after updating our app. We get java.lang.VerifyError exceptions which cause the app to crash at start. It's reproducible when updating Coil from 0.13.0 to 1.0.0 when using current AGP4.1.1 and R8 on API 19 devices only.

I know that the log (see below) suggests that the issue is related to the workmanager, but I guess the app just crashes there because it gets initialized very early on app start. The issue is probably caused by the R8 shrinker. I already tried forcing the latest R8 shrinker (2.1.81, AGP4.1.1 uses 2.1.75 by default) but I had no success. I also tried compiling with Kotlin 1.4.0, 1.4.10 and 1.4.20. So it looks like the bug was under the radar so far.

I am willing to create a ticket on the Google issue tracker too. But I wanted to check what changed on the side of Coil before doing so.

Expected behavior Updating to Coil 1.0.0 should not cause crashes when using latest (stable) AGP and R8.

To Reproduce I can reproduce it locally by just switching between the two Coil versions and building with R8 enabled. If you need a minimal sample project I can try to help you out with that.

Logs/Screenshots

java.lang.VerifyError: 
  at androidx.work.impl.WorkDatabase.create (WorkDatabase.java:117)
  at androidx.work.impl.WorkManagerImpl.<init> (WorkManagerImpl.java:236)
  at androidx.work.impl.WorkManagerImpl.<init> (WorkManagerImpl.java:211)
  at androidx.work.impl.WorkManagerImpl.initialize (WorkManagerImpl.java:190)
  at androidx.work.WorkManager.initialize (WorkManager.java:210)
  at androidx.work.impl.WorkManagerInitializer.onCreate (WorkManagerInitializer.java:40)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1616)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1587)
  at android.app.ActivityThread.installProvider (ActivityThread.java:5199)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:4794)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4734)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:166)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1343)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5590)
  at java.lang.reflect.Method.invokeNative (Method.java)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1268)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
  at dalvik.system.NativeStart.main (NativeStart.java)

Version Happens on real Android 4.4 devices and with current API 19 emulator image.

colinrtwhite commented 3 years ago

I'm able to reproduce this as well in the sample app. Unfortunately I'm not sure how Coil would work around this in its code, however I was able to fix the issue by updating to R8 version 2.2.42 according to this comment and removing -allowaccessmodification.

G00fY2 commented 3 years ago

Thanks for you quick response and taking a look! We ended up switching to proguard-android.txt instead of the proguard-android-optimize.txt default rules as long as we support API19 (we will drop it with beginning of next year anyways). So for anyone else maybe facing this issue, this should do the job.