Android – only use Proguard to disable logging and shrink 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 confuse my code because it brings me a lot of trouble. I just want to delete log calls and enable narrowing 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 above code to proguard-rules.pro works only when I set getdefaultproguardfile ('proguard Android. TXT ') to ('proguard Android optimize. TXT')

But setting it to Proguard - Android - optimize. TXT will enable the optimization flag I don't want

So how do i disable logging and shrink resources without any reduction or optimization of my code by Proguard?

resolvent:

You should be able to achieve this by enabling only specific Proguard optimizations, which may affect their impact. It relies on two:

>Code / remove / simple: delete dead codes based on simple control flow analysis. > code / remove / advanced: delete dead codes based on control flow analysis and data flow analysis

You can read more about different optimization options here. So such things should be effective:

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
        }
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>