java.lang.ClassCastException on Android app after building with Proguard
Closed this issue · 1 comments
We are trying to integrate the Java SDK into our Android app. It works well in debug mode, unfortunately, it doesn't when building the app for a releasable version and using Proguard to minify it.
We keep getting java.lang.ClassCastException
after making a fetch
or observeAndTransform
method call.
We have been debugging and taking a look at the logs and we can see that the debug version makes a few extra calls that never happen on the minified app. They go like this:
/environments/xxxx/locales
/environments/xxxx/content_types
/environments/xxxx/entries?content_type=xxxx&fields.xxxx=xxxx
However, when we minimize the app with Proguard it only runs the 1st call to /environments/master/locales
and then it automatically crashes with java.lang.ClassCastException
.
Any clue what could be going wrong? Our guess is that Proguard is removing something that should not be removed. In our case, we had to add @Keep
to the data model class to prevent the annotations ContentfulEntryModel
and ContentfulField
from being removed.
We have tried calling the endpoint using the next two methods and they both end up with the same result:
client
.fetch(CDAEntry::class.java)
.withContentType("appPromotionalCode")
.where("fields.code", code)
.all()
.items()
.firstOrNull()
//// or
client
.observeAndTransform(PromotionalCode::class.java)
.where("fields.code", code)
.all()
.doOnError { Logger.e(it) }
.blockingFirst()
.firstOrNull()
This is the stacktrace that we are getting:
Fatal Exception: java.lang.ClassCastException:
at com.contentful.java.cda.ResourceFactory.fromResponse(ResourceFactory.java:19)
at com.contentful.java.cda.CDAClient$6.apply(CDAClient.java:19)
at com.contentful.java.cda.CDAClient$6.apply(CDAClient.java:19)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableMap$MapSubscriber.d(FlowableMap.java:9)
at io.reactivex.rxjava3.internal.operators.flowable.AbstractBackpressureThrottlingSubscriber.drain(AbstractBackpressureThrottlingSubscriber.java:49)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableOnBackpressureLatest$BackpressureLatestSubscriber.onNext(FlowableOnBackpressureLatest.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableFromObservable$SubscriberObserver.onNext(FlowableFromObservable.java:2)
at retrofit2.adapter.rxjava3.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:29)
at io.reactivex.rxjava3.core.Observable.subscribe(Observable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableFromObservable.subscribeActual(FlowableFromObservable.java:9)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableOnBackpressureLatest.subscribeActual(FlowableOnBackpressureLatest.java:22)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:31)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap.subscribeActual(FlowableFlatMap.java:94)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:31)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap.subscribeActual(FlowableFlatMap.java:94)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:31)
at io.reactivex.rxjava3.core.Flowable.subscribe(Flowable.java:5)
at io.reactivex.rxjava3.core.Flowable.blockingFirst(Flowable.java:75)
at com.contentful.java.cda.FetchQuery.all(FetchQuery.java:75)
at com.reveri.reverihealth.core.contentful.ContentfulService$getPromotionalCode$2.invokeSuspend(ContentfulService.java:75)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:13)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:107)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:16)
at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java:2)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:93)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:93)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:93)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:93)
Thanks
Closing. We solved it by applying all the rules from this file to our project.
I would suggest updating the README of the repo, because when we read the current message of The ProGuard configuration file is used to minify Android Apps using this library.
it made us believe the rules would be applied by default when integrating the library in our project.