我最近为一个 Android 项目重构了我的包结构,并将 BroadcastReceiver
类移到了另一个包中。但是,我忘记更新 AndroidManifest.xml 中 receiver
标记的 android:name
字段。
此 BroadcastReceiver
用于向客户端发送通知,此严重 错误仅表示未发送任何通知。不幸的是,没有对该文件进行编译时验证,或者似乎抛出任何运行时错误以指示此处的配置错误。
我可以做些什么来验证这些类型的配置吗?也许这些信息可以在单元测试中访问并验证?或者,也许我可以配置更详细的输出以确保将来不会忽视这样的错误?
最佳答案
or, it seems, any runtime error thrown to indicate a misconfiguration here
警告可能会出现在 LogCat 中,但也可能不会,因为广播接收者为零是完全正常的情况。
Is there anything I can do from my side to validate these types of configurations?
您可以 file a feature request让 Lint 验证 list 的这一部分。或者,您可以编写自己的脚本来分析源代码树和 list ,并将其作为自定义 Ant 构建脚本的一部分。
Perhaps this information can be accessed in a unit test and verified?
您可以使用 PackageManager
and queryBroadcastReceivers()
确认您用于广播的 Intent
将解析为 1+ 个接收者。
关于android - AndroidManifest 引用的类未验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774012/