I have been using GSON with proguard enabled in my app. I am saving an object in shared prefs using GSON like this
DriverBalanceStat class
public class DriverBalanceStat {
public Double Balance;
public Integer PendingDays;
public boolean IsMeterBlocked;
public Long BalanceDate;
public double CashbackAmount;
public Boolean IsAllowCashTrip;
public Boolean IsAllowCashlessTrip;
public DriverBalanceStat(Double balance, Integer pendingDays, boolean isMeterBlocked, Long balanceDate,
Double cashbackAmount, Boolean isAllowCashTrip, Boolean isAllowCashlessTrip) {
this.Balance = balance;
this.PendingDays = pendingDays;
this.IsMeterBlocked = isMeterBlocked;
this.BalanceDate = balanceDate;
this.CashbackAmount = cashbackAmount;
this.IsAllowCashTrip = isAllowCashTrip;
this.IsAllowCashlessTrip = isAllowCashlessTrip;
}
}
Setting object in shared pref
public boolean SetAppPrefsByKey(int key, Object value) {
synchronized (this) {
try {
Gson gson = new Gson();
String json = gson.toJson(value);
prefsEdit.putString(context.getString(key), json);
prefsEdit.apply();
return true;
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
return false;
}
}
}
Getting object from shared pref
public Object GetAppObjectByKey(int key, Class<?> cls) {
synchronized (this) {
Gson gson = new Gson();
String json = prefs.getString(context.getString(key), "");
return gson.fromJson(json, cls);
}
}
Whenever i trying to get the values from shared pref using
(DriverBalanceStat) sharedPrefUtil.GetAppObjectByKey(R.string.driver_bal_key, DriverBalanceStat.class)
it throws me fatal error
java.lang.IllegalStateException - Expected an int but was BOOLEAN at line 1 column 24 path $.b
When i logged the values saved in pref i got the following results
without proguard
{"Balance":-35617.2,"BalanceDate":1717503937502,"CashbackAmount":0.0,"IsAllowCashTrip":true,"IsAllowCashlessTrip":true,"IsMeterBlocked":false,"PendingDays":0}
with proguard
{"a":-0.0,"b":false,"c":1717804886626,"d":true,"e":true}
Problem starts only after i upgrade my gradle plugin to 7.4.2
from 4.x.x
kindly suggest. My app is breaking in release version