Sean Connolly
Sean Connolly

Reputation: 5801

android - AndroidManifest referenced classes not validated

I recently refactored my package structure for an Android project and moved a BroadcastReceiver class to a different package. However, I forgot to update the receiver tag's android:name field in the AndroidManifest.xml.

This BroadcastReceiver was used to send notifications to the client and this serious error simply meant that no notifications were sent. Unfortunately there is no compile time validation of this file or, it seems, any runtime error thrown to indicate a misconfiguration here.

Is there anything I can do from my side to validate these types of configurations? Perhaps this information can be accessed in a unit test and verified? Or, perhaps there is more verbose output I can configure to make sure error like this don't go unnoticed in the future?

Upvotes: 1

Views: 99

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007533

or, it seems, any runtime error thrown to indicate a misconfiguration here

A warning might have shown up in LogCat, but probably not, as having zero receivers for a broadcast is a perfectly normal condition.

Is there anything I can do from my side to validate these types of configurations?

You can file a feature request to have Lint validate this portion of the manifest. Or, you can write your own script to analyze your source tree and manifest and include this as part of a customized Ant build script.

Perhaps this information can be accessed in a unit test and verified?

You can use PackageManager and queryBroadcastReceivers() to confirm that the Intent you use for broadcasts will resolve to 1+ receivers.

Upvotes: 1

Related Questions