Monday, 14 March 2022

Using R8 and proguard to remove logging, but turn off everything else

I am trying to use R8 and proguard to remove logging from the release build. The catch is that I need to this be minimally invasive at the moment, so I would like to enable R8/proguard to remove logs, but turn off everything else. IE minifcation, obfuscation, etc.

build.gradle:

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

proguard-rules.pro:

-dontobfuscate
-dontoptimize
-dontshrink

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

However when building and deploying a release build the logs are not removed. I imagine that this is because assumenosideeffects runs as part of one of the options that I turned off.

I have also tried this:

-keep class ** { *; }

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

However that also still leaves logging.

Without moving to a different logging library or modifying code, is is possible to to remove logging with R8/proguard and not run anything else?

EDIT:

I an effort to figure out why proguard/r8 is not removing logs I created a brand new project. I added one line of logging with the following config:

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

However when I build the release version and install the APK I am still seeing logging, which means my log statement was not removed.



from Using R8 and proguard to remove logging, but turn off everything else

No comments:

Post a Comment