Android Project - Using older Android API level causes code smell

I’m using SonarCloud to analyze many Github projects. Most are Android applications in Java, and they use Android API level 27 (29 is the latest).

There is some Android functionality that we use in the API level 27 that has been deprecated in the newest levels (28/29), but for our purposes, we’re happy with 27 for now.

The SonarCloud analysis detects some of our API level 27 functionality as deprecated. This leads me to believe it’s analyzing against the latest Android API. How can I direct the analysis of the project to analyze against a specific Android API level (27 in our case) instead of the current? It’ll be quite time consuming if I have to mark each and every one manually.


I’ll try to get confirmation but I don’t think it’s possible to tel the analyzer which version to target, unless this could be a specific parameter in the rule itself.

But if this rule doesn’t apply to your use case or does too much noise you could also tweak/disable it in the quality profile of your project.

Thanks for your response. Unfortunately the rule does still apply in cases where we are migrating apps from older API levels to a later, but not the latest, API level. For now, it seems I’ll have to handle each code smell individually.
Is there a means of submitting a feature request to SonarSource? It seems this would be popular as not everyone instantly upgrades to the latest API level. With API level 30 in Beta right now, it would be great to at least be able to tell which version we’re checking against.


I confirm what @Gregoire_Aubert said, it is currently not possible to tell which version to target, nor to configure the rule.

In fact, the rule does not target specifically Android, but generically detects the usage of deprecated code by looking at the byte-code of the dependencies. If the rule raises an issue, it means that the code in the dependencies during the analysis is deprecated.
I’m not familiar enough with Android levels, I suspect something Android specific is happening here, do you have a clue?

1 Like