Use Proguard only to disable logging and reduce 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 distort my code as it causes me a lot of problems. I only want to remove the log calls and allow the reduction 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 above code to proguard-rules.proworks only if I set getDefaultProguardFile from ('proguard-android.txt')to('proguard-android-optimize.txt')

But, setting it to proguard-android-optimize.txt, optimization flags will be included, which I do not need in my case.

So, how can I just turn off resource logging and compression without Proguard doing any minimization or optimization of my code?

+4
2

, Proguard, assumenosideeffects. :

  • /​​/: .
  • /​​/: .

. , - :

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

, , -dontobfuscate dontshrink proguard. .

-1

Source: https://habr.com/ru/post/1621597/


All Articles