UnusedAttribute warning while using foregroundServiceType attribute.

309 views
Skip to first unread message

Aditya Vardhan

unread,
Jul 18, 2019, 3:43:44 AM7/18/19
to lint-dev
Hey guys,
                 Lint gives  'UnusedAttribute' warning after adding 'android:foregroundServiceType="location"' to the manifest file. The min SDK version in this case is 21, the target SDK version is 29 and AGP version is 3.4.0.

Is this the expected lint behaviour? Currently, it is handled by adding tools:ignore="UnusedAttribute" /> to suppress the warning, but is that the best solution?

Regards,
Aditya.

Tor Norbye

unread,
Jul 30, 2019, 4:57:38 PM7/30/19
to lint-dev
Normally, referencing a class method or field added in api level X will cause a crash on API levels older than X, so we treat those as errors.
But what about adding an attribute in the manifest, or in a layout file? If nobody looks up that attribute value, there's no crash. ("If a tree falls in a forest and no one is around to hear it, does it make a sound?").
So we could just silently ignore these.

However, the issue is that sometimes the attribute you've added is really important, and you may *think* that it's going to do something vital for your app, yet it has no effect on older versions. That's why this is a warning and we want you to look at it and consider it.

There are a bunch of attributes we know about that we're pretty sure you're okay with treating as benign. We have a hardcoded list of these -- and it sounds like we should just add "foregroundServiceType" to that list.

-- Tor

Steven Schoen

unread,
Jul 30, 2019, 7:23:30 PM7/30/19
to lint-dev
IMO all of the autofill attributes should be added as well.

Tor Norbye

unread,
Jul 30, 2019, 8:07:49 PM7/30/19
to Steven Schoen, lint-dev
importantForAutofill is already on the list; which others do you have in mind? I've created
if you or anyone else would like to nominate unused attributes that you've had to suppress in your own codebase after looking them up and making sure that it's fine for these to be no-ops on older platforms.

-- Tor

On Tue, Jul 30, 2019 at 4:23 PM Steven Schoen <digis...@gmail.com> wrote:
IMO all of the autofill attributes should be added as well.

--
You received this message because you are subscribed to the Google Groups "lint-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lint-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lint-dev/9a3e28b7-adf2-408f-a1db-3939081840ed%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages