我正在尝试测试我的 Android 基于位置的应用程序。
如果我可以在单元测试中模拟来自提供商的位置数据,那将非常有用。但我无法向 androidManifest.xml
添加 ACCESS_MOCK_LOCATION
权限,因为当我这样做时,它会给我一个错误:
Mock locations should only be requested in a debug-specific manifest file (typically src/debug/AndroidManifest.xml) Using a mock location provider (by requiring the permission android.permission.ACCESS_MOCK_LOCATION) should only be done in debug builds. In Gradle projects, that means you should only request this permission in a debug source set specific manifest file. To fix this, create a new manifest file in the debug folder and move the element there. A typical path to a debug manifest override file in a Gradle project is src/debug/AndroidManifest.xml.
但是当我将 AndroidManifest.xml
添加到 src/androidTest
目录时 - 它在测试时会忽略它。
我做错了什么?
最佳答案
我刚刚遇到了这个问题,我想我找到了解决方案。确保在您的设备开发者选项中选中“访问模拟位置”(此外还创建一个“src/debug/AndroidManifest.xml”文件声明 ACCESS_MOCK_LOCATION 权限的使用,就像您已经在做的那样)。
关于java - 使用模拟位置测试应用程序时出现 Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502712/