Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard and Preference DataStore

I use proguard on my project which is used android DataStore. It worked fine without proguard. But when it is obfuscated with proguard the following error occured:

java.lang.RuntimeException: Field preferences_ for f.k.k.h not found. Known fields are [public f.k.k.l.k0 f.k.k.h.i, public static final f.k.k.h f.k.k.h.j, public static volatile f.k.k.l.x0 f.k.k.h.k]
        at f.k.k.l.s0.K(Unknown Source:62)
        at f.k.k.l.s0.y(:6)
        at f.k.k.l.s0.x(Unknown Source:12)
        at f.k.k.l.a1.a(:32)
        at f.k.k.l.a1.b(Unknown Source:4)
        at f.k.k.l.x.r(:4)
        at f.k.k.h.s(:2)
        at f.k.k.k.b(:2)
        at f.k.i.e(Unknown Source:48)
        at f.k.i.f(:2)
        at f.k.i.d(:4)
        at f.k.i$b.e(:4)
        at i.n.j.a.a.l(:2)
        at d.a.p0.run(:4)
        at d.a.f2.a.u(Unknown Source:0)
        at d.a.f2.a$a.run(:7)

There is no proguard rule mentioned in the official document. Should I add some rules to my project to prevent DataStore from obfuscation?

like image 244
AliSh Avatar asked Sep 27 '20 08:09

AliSh


People also ask

Is jetpack DataStore a replacement for SharedPreferences?

Jetpack DataStore is a new and improved data storage solution aimed at replacing SharedPreferences. Built on Kotlin coroutines and Flow, DataStore provides two different implementations: Proto DataStore, that lets you store typed objects (backed by protocol buffers)

What is Preferences DataStore?

Creating a Preferences DataStore DataStore is an interface that grants access to the persisted information. Preferences is an abstract class similar to a generic Map, used specifically in the Preferences implementation of DataStore to keep track of your data's key-value pairs.

What is jetpack DataStore?

Jetpack DataStore is a data storage solution that allows you to store key-value pairs or typed objects with protocol buffers. DataStore uses Kotlin coroutines and Flow to store data asynchronously, consistently, and transactionally.


Video Answer


1 Answers

It was solved when I add the following rule to my project:

-keep class androidx.datastore.*.** {*;}

I have reported it to the google, you can follow it there:

https://issuetracker.google.com/issues/168580258

like image 148
AliSh Avatar answered Nov 15 '22 08:11

AliSh