spotify / android-sdk

Spotify SDK for Android
https://developer.spotify.com/documentation/android/
Apache License 2.0
462 stars 119 forks source link

Too many logs: 'Unable to resolve ***' #226

Open brim-borium opened 4 years ago

brim-borium commented 4 years ago

Issue found on 28.04.2020.

SDK Version:

spotify-app-remote-release-0.7.0

OS Version:

Android

Scope(s):

Using the android sdk for a flutter package

Steps to reproduce:

  1. Run the app with the package

Expected behaviour:

Log is not spammed

Actual behaviour:

Log gets spammed

Log sample

W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/PlayerState; annotation class 1408
[        ] W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/Track; annotation class 1405
[        ] W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/Track; annotation class 1408
[   +3 ms] W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/Track; annotation class 1408
[        ] W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/Album; annotation class 1405
[        ] W/ify_sdk_exampl(28675): Unable to resolve Lcom/spotify/protocol/types/Album; annotation class 1408
mannodermaus commented 1 year ago

I have encountered these particular noisy logs on a totally unrelated OSS project that I maintain (link to the issue in that project). My research eventually led me here, but ultimately not much further. Eventually I was able to fix the issue myself, so I'd like to share my insights in the hopes that it may help y'all as well.

In my library, the annotations of classes are being inspected at runtime using Class.isAnnotationPresent(). During this inspection, one particular annotation was missing from the runtime classpath, yet it declared a retention of RUNTIME. Therefore, ART expected it to be there, and when it wasn't, it highlighted this in a very visible fashion through Logcat. It was a very innocuous annotation for simply marking the API stability from a third-party artifact, but this was enough to trigger a warning deep within the native ART code, every single time that this class was inspected.

The warning itself originates from dex_file_annotations.cc in ART (direct link). This is where any call to Class.isAnnotationPresent() eventually ends up, and when there is no entry for a particular annotation in the dex file, the warning is logged.

My suggestion for how to resolve this in the Spotify SDK:

1) Inspect the annotations on top of classes such as com.spotify.protocol.types.Track* 2) Identify those that have an annotation retention of RUNTIME 3) Double-check that the libraries that they come from are actually added as api, implementation or runtimeOnly dependencies. If not, either add the dependency in this fashion or change the retention of the offending annotation to something else.

I hope this helps!


* From a cursory look at the compiled AAR, it seems like the only annotation on top of the Track class comes from Jackson, the deserialization library. It might be possible to fix the issue by adding their annotation lib as a runtime dependency:

dependencies {
  runtimeOnly("com.fasterxml.jackson.core:jackson-annotations:2.15.2")
}