Skip to content

Issue with R8 minification #402

@adesentenac

Description

@adesentenac

We're using the datetime library 0.6.0 in an internal multiplatform library we use in our app.
The app is minified with R8 (AGP 8.4.2, Gradle 8.6).

If we set dayOfMonth on a DateTimeComponents like this:

val date = formatter.parseOrNull(value)?.apply {
    setOffset(TimeZone.UTC.offset)
    dayOfMonth = 1
}

in our library, our application crashes on launch with the following stacktrace:

java.lang.VerifyError: Verifier rejected class A0.E: void A0.E.k(A0.E) failed to verify: void A0.E.k(A0.E): [0x5] register v0 has type Precise Reference: java.lang.Integer but expected Precise Reference: U0.k (declaration of 'A0.E' appears in .../base.apk)
    at A0.Z1.a(SourceFile:90)
    at A0.b.e(SourceFile:27)
    at A0.b.onAttachedToWindow(SourceFile:17)
    at android.view.View.dispatchAttachedToWindow(View.java:22257)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3494)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3501)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3501)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3501)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3207)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2659)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9789)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1399)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1408)
    at android.view.Choreographer.doCallbacks(Choreographer.java:1008)
    at android.view.Choreographer.doFrame(Choreographer.java:938)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1382)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8501)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

Adding:

-keep,includedescriptorclasses class kotlinx.datetime.format.TwoDigitNumber { *; }

in our proguard-rules.pro file fixed the issue, so I'm sharing this here in case someone else encounter this issue, since it's really not obvious what the issue is from the logs. I have also no idea why R8 fails to keep TwoDigitNumber without the rule.

I'm not sure if anything can be done in the datetime library about this, so if that's the case feel free to close this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions