Skip to content

Instantly share code, notes, and snippets.

@benvium
Last active January 5, 2018 07:57
Show Gist options
  • Save benvium/8995326bc944f47f2c64 to your computer and use it in GitHub Desktop.
Save benvium/8995326bc944f47f2c64 to your computer and use it in GitHub Desktop.
Android proguard file to remove log messages. This is tested and actually works with Android Studio 0.8.8 You need to add some lines to the build.gradle file (see notes below) Includes library-specific rules for Guava, Crashlytics, OkHttp, Retrofit, Otto
######################################################
# Proguard file to remove debug logs and NOT kill the application
#
# @benclayton github.com/benvium 15-12-2014
#
# https://gist.github.com/benvium/8995326bc944f47f2c64
######################################################
# To use this file, your project's build.gradle 'buildTypes' section should look like this:
#
# buildTypes {
# release {
# minifyEnabled true
# proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '../proguard-rules.txt'
#
# the ../proguard-rules.txt should be the location of this file relative to the build.gradle file
#
# You can then build the obfuscated APK using ./gradlew assembleRelease
-keep class * extends android.app.Activity
# --------------------------------------------------------------------
# REMOVE all Log messages except warnings and errors
# --------------------------------------------------------------------
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
}
#==================================================================
# LIBRARY-SPECIFIC RULES
#
# You can remove the sections below if you're not using the libraries in your project,
# though leaving them in works fine.
#==================================================================
#------------------------------------------------------------------
# Google's Guava Library
#------------------------------------------------------------------
-dontwarn com.google.common.**
# --------------------------------------------------------------------
# Crashlytics
# --------------------------------------------------------------------
# http://support.crashlytics.com/knowledgebase/articles/202143-eclipse-with-proguard
-keepattributes SourceFile,LineNumberTable
# --------------------------------------------------------------------
# Square Otto
# --------------------------------------------------------------------
# http://square.github.io/otto/
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
# --------------------------------------------------------------------
# Square OkHttp
# --------------------------------------------------------------------
# https://github.com/levelup/Android-HttpClient/blob/master/HttpClient-OkHttp/proguard-project.txt
-keepnames class com.levelup.http.okhttp.** { *; }
-keepnames interface com.levelup.http.okhttp.** { *; }
-keepnames class com.squareup.okhttp.** { *; }
-keepnames interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.internal.http.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# --------------------------------------------------------------------
# Square Retrofit (uses GSON)
# --------------------------------------------------------------------
# https://github.com/square/retrofit/issues/372
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn rx.**
-keep class com.google.gson.** { *; }
-keep class com.google.inject.* { *; }
-keep class org.apache.http.* { *; }
-keep class org.apache.james.mime4j.* { *; }
-keep class javax.inject.* { *; }
-keep class retrofit.* { *; }
-keep class sun.misc.Unsafe { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
-dontwarn retrofit.appengine.**
# --------------------------------------------------------------------
# IMPORTANT: If you're using GSON or Retrofit you must edit this part
# to prevent your model classes being removed or obfuscated
# --------------------------------------------------------------------
-keep class com.myapp.models.** { *; }
@hai-ld
Copy link

hai-ld commented Jan 7, 2015

Hi Ben,

Thanks for your snippet 😄 Is there any way to ONLY remove log messages without having to config proguard for every single library?

@Prosquid1
Copy link

@hai-Id +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment