disable log in release mode android

363 views Asked by At

I want to disable logcat on release mode and i put below code on build.gradle :

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

and put below code on proguard-rules.repo :

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static *** d(...);
    public static *** w(...);
    public static *** v(...);
    public static *** e(...);
    public static *** i(...);
}

but I can see log too. what should I do? (I tried this code too :

-assumenosideeffects class android.util.Log{*;}

but it didn't work)

1

There are 1 answers

0
Manish Ahire On

I have made constant class as a solution.

public class Log {

static final boolean LOG = BuildConfig.DEBUG;

public static void i(String tag, String string) {
    if (LOG) android.util.Log.i(tag, string);
}

public static void e(String tag, String string) {
    if (LOG) android.util.Log.e(tag, string);
}

public static void d(String tag, String string) {
    if (LOG) android.util.Log.d(tag, string);
}

public static void v(String tag, String string) {
    if (LOG) android.util.Log.v(tag, string);
}

public static void w(String tag, String string, Exception exception) {
    if (LOG) android.util.Log.w(tag, string, exception);
}

}