dokar3 / ChipTextField

Editable chip layout for Compose Multiplatform
Apache License 2.0
82 stars 3 forks source link

Crash on AGP 8.2.0 #113

Closed lepicekmichal closed 6 months ago

lepicekmichal commented 6 months ago

AGP 8.2.0 and the latest version of your library crashes at runtime while minify is enabled and debuggable disabled. But seriously, why is reflection used in this library?

Non-fatal Exception: java.lang.NoSuchFieldException: No field focusedTextColor in class Landroidx/compose/material3/cd; (declaration of 'androidx.compose.material3.cd' appears in /data/app/~~T11x0NL06y8UFu6aZRE_2A==/eu.lepicekmichal.fooswars-uWw35dXM74BkibnmcsOXAQ==/base.apk)
       at java.lang.Class.getDeclaredField(Class.java)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt$textFieldColorsFields$2.invoke$field(TextFieldColorsConverter.kt:120)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt$textFieldColorsFields$2.invoke(TextFieldColorsConverter.kt:122)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt$textFieldColorsFields$2.invoke(TextFieldColorsConverter.kt:118)
       at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt.getTextFieldColorsFields(TextFieldColorsConverter.kt:118)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt.readColors(TextFieldColorsConverter.kt:82)
       at com.dokar.chiptextfield.m3.TextFieldColorsConverterKt.toChipTextFieldColors(TextFieldColorsConverter.kt:16)
       at com.dokar.chiptextfield.m3.ChipTextFieldKt.ChipTextField-ssrxHw0(ChipTextField.kt:290)
       at com.dokar.chiptextfield.m3.ChipTextFieldKt.ChipTextField-ssrxHw0(ChipTextField.kt:200)
dokar3 commented 6 months ago

Just confirmed this, could you add this proguard rule as a temporary workaround?

-keepclassmembernames class androidx.compose.material3.TextFieldColors { *; }

Reflection is needed because m3 text field colors are private, so they cannot be used directly for the chip text fields.

In the next version, I will try to use the suppress annotation to access internal color functions so we can get rid of reflection, hopefully.

dokar3 commented 6 months ago

The new version is out. https://github.com/dokar3/ChipTextField/releases/tag/v0.6.4