Skip to content

Issue with R8 minification #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adesentenac opened this issue Jun 25, 2024 · 4 comments
Closed

Issue with R8 minification #402

adesentenac opened this issue Jun 25, 2024 · 4 comments

Comments

@adesentenac
Copy link

adesentenac commented Jun 25, 2024

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.

@dkhalanskyjb
Copy link
Collaborator

Strange. We are not doing anything fancy with TwoDigitNumber. Filed an issue for Android: https://issuetracker.google.com/issues/351858994

@dkhalanskyjb dkhalanskyjb closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
@dkhalanskyjb
Copy link
Collaborator

@adesentenac, we have a reply from Google: https://issuetracker.google.com/issues/351858994#comment2 Could you obtain the dump and send it either here (I'll resend relay it to the Android issue tracker) or directly there? I suppose a self-contained project where the issue reproduces is fine, too.

@sgjesse
Copy link

sgjesse commented Aug 29, 2024

@adesentenac, I am still interested in this issue. Can you provide a small reproduction (or share a dump of a failing project). If I just add this code to a Kotlin app and build a release version with minifyEnabled = true it runs fine.

        val formatter = DateTimeComponents.Format { date(LocalDate.Formats.ISO) }
        val value = "2024-10-10"
        val date = formatter.parseOrNull(value)?.apply {
            setOffset(TimeZone.UTC.offset)
            dayOfMonth = 1
        }
        println("Test: " + date?.dayOfMonth)

@prof18
Copy link

prof18 commented Apr 6, 2025

Hi @dkhalanskyjb,

I've run into the same issue while trying to update to new AGP my project (https://github.com/prof18/feed-flow/tree/date-time-r8-issue)

I've build up an easier reproducer, you can find it here: https://github.com/prof18/DateTimeR8IssueRepro

I left the same comment in the Google Tracker, lemme know if you prefer that I open a new issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants