Problem: Android local database doesn't work when I make a signed APK.
More Info: I tried to use the room database, it failed. I then tried Sugar ORM, still, it failed.
Everything works perfectly in debug mode until I make a signed APK. It cannot write or read from the local database. I have updated Android Studio but still, fail.
It's because of proguard obfuscation. Add your database models to
proguard-rules.profile to prevent them from being obfuscated during the build. For example, you have a class called ContactModel.java for your contacts table like so:And the address of the class is
com.example.myapp.model.ContactModel.java. You should add a rule toproguard-rules.prolike this:If you have a lot of classes and you don't want to add them one by one you just need to add all of them to one package; for example
model, and then put*instead of the class name at the end of the address like so: