1

我最近为一个 Android 项目重构了我的包结构,并将一个BroadcastReceiver类移到了另一个包中。但是,我忘记更新 AndroidManifest.xml 中的receiver标签android:name字段。

BroadcastReceiver是用来向客户端发送通知的,这个严重的错误仅仅意味着没有发送通知。不幸的是,没有对该文件进行编译时验证,或者似乎抛出了任何运行时错误以指示此处的配置错误。

我能做些什么来验证这些类型的配置吗?也许这些信息可以在单元测试中访问并验证?或者,也许我可以配置更详细的输出以确保这样的错误将来不会被忽视?

4

1 回答 1

1

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.

于 2013-02-08T14:21:55.030 回答