简体   繁体   中英

Android compilation error after upgrading to 'com.google.android.gms:play-services-ads:18.1.0'

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?

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 (eg, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM