Search code examples
androidandroid-proguard

ProGuard obviously does not run


I try to do some code optimization with proguard, but have not been successful until now. All the answers to similar questions on SO did not help me and the documentation regarding proguard provided by google isn't very helpful, too.

What I did:

I have the following in my build.gradle at the app-level:

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

In my proguard-rules.pro I have added this:

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

I did not change anything in the proguard-android-optimize.txt file.

Now when I build a signed release apk (Android Studio 3.0) the decompiled result shows that nothing has changed in my code and there is no output of proguard visible (not in the app/build/intermediates-folder and not in the gradle console). I am sure I am missing something quite simple but I cannot figure it out.

Is there anything else that I have to configure to get proguard running?


Solution

  • OK, seems like I've been a victim of not remembering "Did you try to turn it off and on again?"

    Today I started my machine, opened Android Studio and everything worked like a charm. Looks like there are some things cached in Android Studio, Gradle, ProGuard, whatever, so my previous erroneous tries left everything in an unstable state where nothing worked.

    So if anyone has a similar setup (Android Studio 3.0 with Gradle 4.1) with the exact configuration as stated above and things do not work:

    "Try to turn it off and on again".

    :-)

    (And not just Android Studio as this is what I did yesterday without success.)