1

I am upgrading my play-services-ads library from version 12 to version 18.1:

dependencies {
    api 'com.google.android.gms:play-services-ads:18.1.0'
}

The problem is that the compilation fails with this error:

.gradle/caches/transforms-1/files-1.1/play-services-ads-identifier-17.0.0.aar/75b3c9fbdc51199269673bd2fa8b6cfe/jars/classes.jar(com/google/android/gms/ads/identifier/AdvertisingIdClient.class): warning: Cannot find annotation method 'value()' in type 'GuardedBy': class file for javax.annotation.concurrent.GuardedBy not found

I took away all the usages for AdvertisingIdClient and left only the import, but the problem persists:

import com.google.android.gms.ads.identifier.AdvertisingIdClient;

Is there anything I am doing wrong?

Doron Yakovlev Golani
  • 4,748
  • 9
  • 35
  • 55
  • The class mentioned in the error (`javax.annotation.concurrent.GuardedBy`) does not seem to exist in the Android SDK. There are other versions of that class, [such as `androidx.annotation.GuardedBy`](https://developer.android.com/reference/androidx/annotation/GuardedBy). Based on [this old bug report](https://github.com/androidannotations/androidannotations/issues/707), try adding `implementation "com.google.code.findbugs:jsr305:3.0.2"` to your dependencies, and see if that helps. – CommonsWare Jul 19 '19 at 19:26
  • It works! Now I am wondering how... @CommonsWare could you please explain what is going on? – Doron Yakovlev Golani Jul 19 '19 at 20:01
  • The AAR for `play-services-basement` includes a `proguard.txt` that specifies: `-dontwarn javax.annotation.**` That should allow your app to ProGuard successfully whether or not you include a dependency that includes `javax.annotation.concurrent.GuardedBy` Can you say what exact gradle task is failing? Also, what version of Android Studio, gradle, and `com.android.tools.build:gradle` are you using? – jkasnicki Jul 22 '19 at 15:41
  • @ jkasnicki - classpath 'com.android.tools.build:gradle:3.4.2' – Doron Yakovlev Golani Jul 22 '19 at 18:40
  • @jkasnicki Task :mpsrv:compileDebugJavaWithJavac FAILED. – Doron Yakovlev Golani Jul 23 '19 at 12:45
  • I can't repro with a fresh project adding the dependency and import. Is it possible to get a minimal reproducing project, for example on github? – jkasnicki Jul 25 '19 at 22:50

1 Answers1

1

com.google.android.gms:play-services-ads:18.1.0 depends upon com.google.android.gms:play-services-ads-identifier:17.0.0, among other libraries.

Your error indicates that com.google.android.gms:play-services-ads-identifier:17.0.0 references javax.annotation.concurrent.GuardedBy. However, that class is not in the Android SDK. The POM file for com.google.android.gms:play-services-ads-identifier:17.0.0 should be referencing a library that has an implementation of that class, but it does not seem to.

One library that has an implementation of that class is com.google.code.findbugs:jsr305. Adding a dependency on com.google.code.findbugs:jsr305 for a recent version (e.g., 3.0.2) gave you that class, satisfying the compiler.

So, there appears to be a bug in the Play Services SDK packaging, which my workaround resolves. You might want to add a comment in your module's build.gradle file to consider removing the com.google.code.findbugs:jsr305 if a future update to com.google.android.gms:play-services-ads fixes this bug.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367