I have an Android App, which receives data via an JSON Api.
I then convert the data with Jackson ObjectMapper.
I also included com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0
in my build.gradle to ensure LocalDates are handled properly.
Important: As long as i run the App via Android-Studio (by RUN or DEBUG) everything works as expected.
But if i generate a signed APK in release mode and install it manually on the phone jackson complains about a missing constructor for the LocalDate class. It behaves, as if the additional time desirializer in the datatype-jsr310 were not included in the Build?!
i have proguard enabled also in debugmode (exactly for this kind of things to test). Also analyzing the APK shows that the jsr310 classes are included.
here is my build Section of gradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
//debuggable = true
}
debug {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
i also tried to configure Proguard to ignore jackson:
-keep interface com.fasterxml** {
<fields>;
<methods>;
}
-keep class com.fasterxml** {
<fields>;
<methods>;
}
Stacktrace in LogCat with the release apk running:
2020-06-15 14:25:15.732 14035-14082/? W/System.err: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.LocalDate` (no Creators, like default constructor, exist): no String-argument constructor/factory method to deserialize from String value ('2019-02-28')
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.my.model.modules.Timeline["dates"]->java.util.ArrayList[0])
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(Unknown Source:2)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(Unknown Source:4)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(Unknown Source:124)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(Unknown Source:73)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(Unknown Source:4)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(Unknown Source:47)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(Unknown Source:63)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(Unknown Source:40)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(Unknown Source:55)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(Unknown Source:48)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(Unknown Source:0)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(Unknown Source:26)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(Unknown Source:31)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(Unknown Source:14)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(Unknown Source:56)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.fasterxml.jackson.databind.ObjectReader.readValue(Unknown Source:21)
2020-06-15 14:25:15.732 14035-14082/? W/System.err: at com.my.android.app.net.ws.WsQueueManager.transformFacade(Unknown Source:52)
The DTO is a simple class with a List of Dates:
public class Timeline implements Serializable {
// @JsonDeserialize(contentAs = LocalDate.class)
// @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
// ^
// | tried both annotations separated and together with same result
public List<LocalDate> dates;
public LevelTimeline() {
}
public List<LocalDate> getDates() {
return dates;
}
public void setDates(List<LocalDate> dates) {
this.dates = dates;
}
}
Finally the Question
How can the release version differ from the debug-version.
Proguard shrinking seems not to be the case, as the classes are available?!
Can this be something else proguard related?
Any Help or hint is appreciated!!