title: Android Studio Gradle proguard - only obfuscate the actual app code and not third libraries
body: <p>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.</p>
  
  <p>The first step I did was to alter my graddle file:</p>
  
  <pre><code>release {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-myapp.txt'
          }
  </code></pre>
  
  <p>The file <code>proguard-myapp.txt</code> is located in my project.</p>
  
  <p>My project uses the following:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>I've kept playing with proguard rules but the more I test the more it gets out of hand.</p>
  
  <p>I've added the following rules:</p>
  
  <pre><code>-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.** { *; }
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>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?</li>
  </ol>
  
  <p>2.I have tried adding as rules only:</p>
  
  <pre><code>-keep class !com.mypackage.**{*;}
  </code></pre>
  
  <p>While the code looks fine on decompile, the app does not work properly.</p>