46

So it looks like there is a bug in the latest play-services to be deployed. Does anyone know how to work around this issue?

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myappname:transformClassesWithAndroidGradleClassShrinkerForDevelopmentDebug'.
> ProGuard configuration parser error: /Users/myusername/.gradle/caches/transforms-1/files-1.1/play-services-base-11.8.0.aar/d2ad9e16677fda9cf07a1280a66e91ca/proguard.txt line 3:88 no viable alternative at input '<fields>'

So more information. seems the problem is in the core module:

Error:Execution failed for task ':myappname:transformClassesWithAndroidGradleClassShrinkerForDevelopmentDebug'.
> ProGuard configuration parser error: /Users/myusername/.gradle/caches/transforms-1/files-1.1/play-services-base-11.8.0.aar/d2ad9e16677fda9cf07a1280a66e91ca/proguard.txt line 3:88 no viable alternative at input '<fields>'

EDIT: The contents of the file that is causing that error is:

# b/35135904 Ensure that proguard will not strip the mResultGuardian.
-keepclassmembers class com.google.android.gms.common.api.internal.BasePendingResult {
  com.google.android.gms.common.api.internal.BasePendingResult.ReleasableResultGuardian <fields>;
}
Brill Pappin
  • 4,692
  • 1
  • 36
  • 36
  • 2
    I have filed an issue to google using https://issuetracker.google.com/issues/73439020 – Elye Feb 16 '18 at 12:15

4 Answers4

74

It seems the default shrinker has changed. Adding the configuration to turn on ProGuard seemed to work.

buildTypes {
        release {
            debuggable false
            minifyEnabled true
            useProguard true
            ...
        }
        debug {
            debuggable true
            minifyEnabled true
            useProguard true
            ...
        }
    }
Brill Pappin
  • 4,692
  • 1
  • 36
  • 36
  • I'm not marking this answer as the correct answer until I get some verification. – Brill Pappin Dec 19 '17 at 20:37
  • 1
    If proguard is enabled for debug builds, how am I supposed to read the logs if they are obfuscated? – Thomas Vos Dec 23 '17 at 12:36
  • 1
    @ThomasVos i'm not sure what you mean, i don't have any trouble reading them. I typically have minify enabled myself, because its too easy to get things into a state, where your dev and prod builds don't match. – Brill Pappin Dec 23 '17 at 15:30
  • This worked for me after updating to the latest build tools and updating my library dependencies. – Thunderstick Jan 30 '18 at 19:18
  • @ThomasVos I am adding to specific rules in debug mode (`-dontoptimize , -dontobfuscate`) which should solve this issue. This way minification is enabled and should show issues for it. – da_berni Feb 12 '18 at 10:42
  • 3
    @BrillPappin I feel the need to fly to Canada to buy you a beer... This issue has plagued me for a month. Thanks! – Andrew G Feb 22 '18 at 22:10
11

In addition to the above solution (which works): the issue seems related to Instant Run as well. If you disable Instant Run, you can build your app without changing your build.gradle. Probably, the default shrinker has changed only when building for Instant Run.

Carlo Conserva
  • 273
  • 3
  • 8
2

This solution helped me:

First, in app/build.gradle change useProguard to 'true'

Second, in proguard rules add line '-dontobfuscate'

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

proguard-rules.pro

-dontobfuscate

So, minify would be work, but code wouldn't obfuscate.

Eduard Kornev
  • 554
  • 4
  • 21
  • It is a generally bad practice to force your code to not obfuscate. If someone got the .apk for your project, they would be able to essentially decompile it into its source code. – LukeWaggoner Apr 11 '18 at 21:46
  • @LukeWaggoner Course, but for qa/debug builds we can not obfuscate code for increase build time. The main question and answer was not about this. – Eduard Kornev Apr 12 '18 at 06:05
  • If that's what you want to do, just set `minifyEnabled` to `false` in your buildType. – LukeWaggoner Apr 12 '18 at 18:29
  • @LukeWaggoner Bad version, cause qa version would be very different than release. For example our qa testers required from team the same apk as release. Our dispute does not make sense, because the question was about something else. My solution is suitable for some of the problems described above. Your remark to the original question does not apply. Everyone knows about obfuscation, but there are times when you need to do otherwise. – Eduard Kornev Apr 13 '18 at 07:47
  • If you have -dontobfuscate set in your proguard, your QA people would already be testing a very different version. Nearly all of the issues I've encountered in minification are related to obfuscating. I see no reason to ever set -dontobfuscate in your code. Especially to fix an issue. What are you going to do when you need to release? Just leave it unobfuscated and vulnerable? – LukeWaggoner Apr 13 '18 at 16:05
1

I am noticing that if you disable Instant Run the build still fails with the same error (if you have minify enabled but Proguard disabled to shrink your code to avoid multi-dex in the debug build). If you follow Brill Pappin answer you must enable Instant Run(and install libraries as prompted) to hit any breakpoints while debugging.
It seems enabling the shrinker as described in the Google docs now only works if you are using Instant Run with the Google Play Play Services.

Will
  • 76
  • 1
  • 5