以下是问题的解决方法:
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
中添加模拟位置权限debug { debuggable true }
)adb shell pm grant com.myapp.name android.permission.ACCESS_MOCK_LOCATION
该命令的结果是:
不允许操作: java.lang.SecurityException:权限android.permission.ACCESS_MOCK_LOCATION不是可更改的权限类型“
如果我在电话中使用开发人员选项并设置Setting >> Developer Option >> Select Mock location app
,它就能工作。
我需要这个自动测试,所以很明显,选择去手机设置是无效的,因为它是重置的每一个应用程序,所以我需要亚行选项的工作。
发布于 2016-07-26 10:23:30
我在Calabash修复程序中找到了相同问题的解决方案:https://github.com/calabash/calabash-android/commit/b31be97953325383b9295ff52234a0121cc27e27
adb shell appops set com.myapp.name 58 allow
要从gradle自动完成此操作,可以将该命令添加到安装任务中:
def adb = android.getAdbExe().toString()
tasks.whenTaskAdded { task ->
if (task.name.startsWith('install')) {
task.doLast {
android.applicationVariants.all { variant ->
"${adb} devices".execute().text.eachLine {
if (it.endsWith("device")) {
def device = it.split()[0]
println "Granting test permissions on device ${device}\n"
"${adb} shell appops set ${variant.applicationId} 58 allow".execute()
}
}
}
}
}
}
但是,您必须在connectedTest任务之前明确地调用安装任务,例如:
gradlew installMyAppDebug connectedMyAppDebugAndroidTest
发布于 2017-04-05 07:45:25
或者,您可以使用Test插件来管理测试权限以及https://github.com/linkedin/test-butler
配置和使用Test的示例项目:https://github.com/sebaslogen/Blendletje/
public class TestRunner extends AndroidJUnitRunner {
@Override
public void onStart() {
TestButler.setup(InstrumentationRegistry.getTargetContext());
super.onStart();
}
@Override
public void finish(final int resultCode, final Bundle results) {
TestButler.teardown(InstrumentationRegistry.getTargetContext());
super.finish(resultCode, results);
}
}
@Before
public void setUp() throws Exception {
final Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
TestButler.verifyAnimationsDisabled(targetContext);
}
您可以看到它是如何在运行测试时自动安装的:https://github.com/sebaslogen/Blendletje/blob/master/app/build.gradle#L107
https://stackoverflow.com/questions/38586678
复制相似问题