2

Since I decompiled my app I noticed that all the members, classes are easy to read and understand, so my goal is to make it harder for someone who decompiles the app, to read the code.

The first step I did was to alter my graddle file:

release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-myapp.txt'
        }

The file proguard-myapp.txt is located in my project.

My project uses the following:

dependencies {
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.android.gms:play-services-ads:9.2.1'
    compile 'com.github.lecho:hellocharts-library:1.5.8@aar'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.1@aar') {
        transitive = true;
    }
}

I've kept playing with proguard rules but the more I test the more it gets out of hand.

I've added the following rules:

-dontshrink
-dontoptimize

#charts
-keep class lecho.lib.hellocharts.** { *; }

#support library
-dontwarn android.support.**
-keep class android.support.** { *; }

#ads
-keep public class com.google.android.gms.ads.** {
   public *;
}

-keep public class com.google.ads.** {
   public *;
}

#gson
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer



#Crashlytics
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keep class io.fabric.sdk.** { *; }

My questions are:

  1. Is it possible to only obfuscate/optimize or whatever it is called, only the files that I actually use in the app, the ones I wrote and leave all the other libraries as they are? I mean, only rename, optimize my classes and my files and ignore crashlytics, admob, support library?

2.I have tried adding as rules only:

-keep class !com.mypackage.**{*;}

While the code looks fine on decompile, the app does not work properly.

Alin
  • 14,809
  • 40
  • 129
  • 218

1 Answers1

1

This may not seem as a proper answer but I found out the reason my compiled app did not work.

After a lot of trying to find out what's wrong, I finally got it working. GSON as it seems in this answer https://stackoverflow.com/a/30982197/379865 needs to have the classes kept in order to properly work. After keeping my classes for the objects related to Gson, it works.

Community
  • 1
  • 1
Alin
  • 14,809
  • 40
  • 129
  • 218