https://kotlinlang.org logo
#android
Title
# android
l

LeoColman

02/18/2019, 11:34 PM
Is this actually a thing?
🚫 2
g

ghedeon

02/19/2019, 12:19 AM
The OP had a specific requirement to not obfuscate data classes at all. To whitelist them in one batch, like
data class
is a type or something. Do you have similar restrictions?
l

LeoColman

02/19/2019, 2:19 AM
I don't have any restriction. My app is just crashing when trying to cast a Data Class to itself. Randomly crashes
d

Dico

02/19/2019, 4:45 AM
I think theres an alternative to proguard that works better
Dont quote me on that though
With kotlin*
k

kassim

02/19/2019, 7:17 AM
what does “randomly crashes” mean? is it a new exception each time? is it in a new line of the code each time? you should make a Stack Overflow post I think also, the alternative to Proguard from Google that perhaps Dico was referring to is called R8 (but I don’t have any info to know that its better for Kotlin or not)
j

Jay

02/19/2019, 9:28 AM
I’m new to Android but I’ve used ProGuard before back in the J2ME days circa 2003. It’s a mature well tested project, and as far as I know it operates directly on bytecode. I’d be surprised if it contains fundamental bugs of this sort. However, I don’t know how Kotlin maps things like data classes into Java bytecode so I’m not saying it’s definitely not an issue. I’d write a minimal example to see if it’s reproducible. Doing this might help you realise an issue on your side (or prove that it’s a bug).
l

LeoColman

02/19/2019, 12:20 PM
The random crashes is that the same line of code (a cast of a Sealed class to a Data Class that inherits it) works, unless it's an OnRestoreInstance, in which Proguard screws up and I get a class cast exception (something like
a.b.c$a
cannot be cast to
a.b.c$b
. If I add
@Keep
to the data class, it works
IDK if this is a bug in pro guard or if I'm doing something wrong
k

kassim

02/19/2019, 1:02 PM
maybe check the proguard mapping file to see what the classes are you can also decompile to see the code where it happens
z

zokipirlo

02/19/2019, 2:47 PM
I'm using `data class`es with Proguard and don't see any problems in production.