1

I'm trying to obfuscate my android app but when i do generate apk as a release and run on the device then my firebase field names are get changed. And also some fields data is not uploaded to the firebase real time database for example System.currentTimeMillisecond(), passwd.

My application works fine without obfuscation and inserts all data properly. After obfuscation it behaves incorrectly and doesn't insert some data properly into firebase.

Expected node:

-userid
 -name:"abc"
 -age:15
 -passwd:"pass@123"
 -timestamp:16003243241

After obfuscate:

-userid
 -a:"abc"
 -b:15

My UserModel class

public class UserModel{
    
    public int age;
    public String name,passwd;
    public long timestamp;

    public UserModel(){}
    public UserModel(String name, String passwd, int age, long timestamp){
        this.name=name;
        this.passwd=passwd;
        this.age=age;
        this.timestamp=timestamp;
    }
}

I have applied into build.gradle: app

buildTypes {
        release {
            minifyEnabled true
            shrinkResources=true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

Proguard:

-keep class yourpackage.** { *; }
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

I have min sdk 23 and target 28. Please help me obfuscate data properly.

Nikita K
  • 75
  • 2
  • 11
  • Are you using GSON for serialization/deserialization – Jack Sep 29 '21 at 07:15
  • Add your code for data model class too – Jack Sep 29 '21 at 07:22
  • Try adding the rule in proguard rules `-keep class com.yourpackage.UserModel` replace `yourpackage` with the right package name for the model class – Jack Sep 29 '21 at 07:29
  • Where is `UserModel` located? Ar you sure you are using the correct package name? – Alex Mamo Sep 29 '21 at 07:29
  • @AlexMamo it is inside the subpackage (named firebase) of main app package (com.myapp). Full path is : com.myapp.firebase.UserModel.java – Nikita K Sep 29 '21 at 07:33
  • In that case, you should use `-keepclassmembers com.myapp.firebase.UserModel** { *; }`. For more info, check [this](https://stackoverflow.com/questions/60719791/firebase-firestore-variable-name-changed/60719948#60719948) out. Does it work this way? – Alex Mamo Sep 29 '21 at 07:37
  • @AlexMamo can you please correct my rules / gradle and rewrite answer. I have other 2 firebase models too. How do i write this rule for MathModel, BookModel on the same package? Should i keep old rules? – Nikita K Sep 29 '21 at 07:44
  • Show us the global rules in your Proguard file. – Alex Mamo Sep 29 '21 at 07:49
  • @AlexMamo try to answer questions instead of comment. This website threatening me block account by showing "no answers from long. account at risk " :( – Nikita K Aug 12 '22 at 15:16
  • @kattie Check the link in my comment above. – Alex Mamo Aug 12 '22 at 15:56

0 Answers0