Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Proguard only to disable logging and for shrinking resources

build.gradle:

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.SginConfig
        }
}

I don't want Proguard to optimize, or obfuscates my code as it is causing me a lot of trouble. I only want to remove log calls and enable shrinking of unused resources.

proguard-rules.pro:

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

Adding the code above to proguard-rules.pro work only if I set getDefaultProguardFile from ('proguard-android.txt') to ('proguard-android-optimize.txt')

But by setting it to proguard-android-optimize.txt would enable optimization flags which I don't want in my case.

So how can I just disable logging and shrink resources without Proguard's doing any minifying or optimizations to my code?

like image 883
Gayan Weerakutti Avatar asked Oct 18 '22 19:10

Gayan Weerakutti


1 Answers

You should be able to do this by only enabling the specific Proguard optimizations that assumenosideeffects depends on. The two that it depends on are:

  • code/removal/simple: Removes dead code based on a simple control flow analysis.
  • code/removal/advanced: Removes dead code based on control flow analysis and data flow analysis.

You can read more about the different optimization options here. So something like this should work:

proguard-rules.pro

-optimizations code/removal/simple,code/removal/advanced
-dontobfuscate
-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

build.gradle

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.SginConfig
        }
}
like image 74
Bradford2000 Avatar answered Oct 29 '22 15:10

Bradford2000