出现这种问题,一种常见的解决方法是通过检查“开发商选项”中的GPU设置来解决。您可以按照以下步骤关闭GPU加速:
此外,您可以尝试在运行模拟器时使用其他选项,例如使用ARM映像,或将硬件加速选项切换为软件加速。
以下是一个使用ARM映像运行模拟器的代码示例:
在build.gradle文件中添加以下configurations:
android {
defaultConfig {
...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: true
testInstrumentationRunnerArguments grantRuntimePermissions: true
testInstrumentationRunnerArguments disallowUninstall: true
testInstrumentationRunnerArguments useTestInstaller: true
}
...
testOptions {
unitTests {
includeAndroidResources = true
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support" && !requested.name.startsWith("multidex")) {
details.useVersion "26.1.0"
}
if (requested.group == "com.android.support.test" && requested.name.startsWith("runner")) {
details.useVersion "1.0.0"
}
if (requested.group == "com.android.support.test" &&