Android工具测试无法安装APK

qyzbxkaa  于 2023-03-11  发布在  Android
关注(0)|答案(4)|浏览(354)

我想运行工具测试作为我的CI管道的一部分,但当我运行测试时,测试失败,因为APK无法安装(据我所知):

> Task :app:connectedDebugAndroidTest FAILED
Mar 18, 2022 3:00:59 PM com.google.testing.platform.RunnerImpl run
SEVERE: Test execution failed with fatal error!
com.google.testing.platform.api.plugin.PluginException: Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:216)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow$default(PluginLifecycle.kt:205)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:92)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:88)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycle.onBeforeAll(PluginLifecycle.kt:88)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor.runUnlessCancelled(SingleDeviceExecutor.kt:105)
        at com.google.testing.platform.executor.SingleDeviceExecutor.execute(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.RunnerImpl.run(RunnerImpl.kt:108)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:80)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy.run(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.main.MainKt$main$4.invokeSuspend(Main.kt:67)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at com.google.testing.platform.main.MainKt.main(Main.kt:66)
        at com.google.testing.platform.main.MainKt.main$default(Main.kt:34)
        at com.google.testing.platform.main.MainKt.main(Main.kt)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.google.testing.platform.launcher.Launcher.main(Launcher.java:149)
Caused by: com.google.testing.platform.core.error.UtpException: ErrorName: UNKNOWN
NameSpace: DdmlibAndroidDeviceController
ErrorCode: 1
Message: Failed to install APKs: UNKNOWN
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController$executeAsync$deferred$1.invokeSuspend(DdmlibAndroidDeviceController.kt:197)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: com.android.ddmlib.InstallException: Unknown failure: Exception occurred while executing 'install':
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.pm.PackageManagerInternal.freeStorage(java.lang.String, long, int)' on a null object reference
at com.android.server.StorageManagerService.allocateBytes(StorageManagerService.java:4033)
at android.os.storage.StorageManager.allocateBytes(StorageManager.java:2340)
at android.os.storage.StorageManager.allocateBytes(StorageManager.java:2419)
at com.android.server.pm.PackageInstallerSession.doWriteInternal(PackageInstallerSession.java:1556)
at com.android.server.pm.PackageInstallerSession.write(PackageInstallerSession.java:1469)
at android.content.pm.PackageInstaller$Session.write(PackageInstaller.java:1045)
at com.android.server.pm.PackageManagerShellCommand.doWriteSplit(PackageManagerShellCommand.java:3338)
at com.android.server.pm.PackageManagerShellCommand.doWriteSplits(PackageManagerShellCommand.java:3300)
at com.android.server.pm.PackageManagerShellCommand.doRunInstall(PackageManagerShellCommand.java:1351)
at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:1303)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:193)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:24742)
at android.os.Binder.shellCommand(Binder.java:950)
at android.os.Binder.onTransact(Binder.java:834)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4818)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:8839)
at android.os.Binder.execTransactInternal(Binder.java:1184)
at android.os.Binder.execTransact(Binder.java:1143)
        at com.android.ddmlib.internal.DeviceImpl.installRemotePackage(DeviceImpl.java:1314)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1140)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDevice.installPackage(DdmlibAndroidDevice.kt)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController$executeAsync$deferred$1.invokeSuspend(DdmlibAndroidDeviceController.kt:166)
        ... 6 more

Mar 18, 2022 3:00:59 PM com.android.tools.utp.plugins.host.additionaltestoutput.AndroidAdditionalTestOutputPlugin deviceShellAndCheckSuccess
WARNING: Shell command failed (1): ls "/sdcard/Android/media/xxxxx/additional_test_output"
ls: /sdcard/Android/media/xxxxx/additional_test_output: No such file or directory

Mar 18, 2022 3:00:59 PM com.android.tools.utp.plugins.host.additionaltestoutput.AndroidAdditionalTestOutputPlugin afterAll
WARNING: Failed to retrieve additional test outputs from device.
com.android.ddmlib.SyncException: Remote object doesn't exist!
        at com.android.ddmlib.SyncService.pullFile(SyncService.java:341)
        at com.android.ddmlib.internal.DeviceImpl.pullFile(DeviceImpl.java:1083)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDevice.pullFile(DdmlibAndroidDevice.kt)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController.pull(DdmlibAndroidDeviceController.kt:254)
        at com.google.testing.platform.executor.DeviceControllerProxy$pull$2.invoke(DeviceControllerProxy.kt:82)
        at com.google.testing.platform.executor.DeviceControllerProxy$pull$2.invoke(DeviceControllerProxy.kt:82)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
        at com.google.testing.platform.executor.DeviceControllerProxy.pull(DeviceControllerProxy.kt:79)
        at com.android.tools.utp.plugins.host.additionaltestoutput.AndroidAdditionalTestOutputPlugin.copyAdditionalTestOutputsFromDeviceToHost(AndroidAdditionalTestOutputPlugin.kt:222)
        at com.android.tools.utp.plugins.host.additionaltestoutput.AndroidAdditionalTestOutputPlugin.afterAll(AndroidAdditionalTestOutputPlugin.kt:206)
        at com.google.testing.platform.plugin.PluginLifecycle$onAfterAll$1$2$1.invoke(PluginLifecycle.kt:180)
        at com.google.testing.platform.plugin.PluginLifecycle$onAfterAll$1$2$1.invoke(PluginLifecycle.kt:179)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:213)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:212)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:212)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow$default(PluginLifecycle.kt:205)
        at com.google.testing.platform.plugin.PluginLifecycle$onAfterAll$1.invoke(PluginLifecycle.kt:179)
        at com.google.testing.platform.plugin.PluginLifecycle$onAfterAll$1.invoke(PluginLifecycle.kt:173)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycle.onAfterAll(PluginLifecycle.kt:173)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$3.invoke(SingleDeviceExecutor.kt:83)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$3.invoke(SingleDeviceExecutor.kt:82)
        at com.google.testing.platform.result.TestResultListenerManager.afterTestSuite(TestResultListenerManager.kt:140)
        at com.google.testing.platform.RunnerImpl.run(RunnerImpl.kt:118)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:80)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy.run(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.main.MainKt$main$4.invokeSuspend(Main.kt:67)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at com.google.testing.platform.main.MainKt.main(Main.kt:66)
        at com.google.testing.platform.main.MainKt.main$default(Main.kt:34)
        at com.google.testing.platform.main.MainKt.main(Main.kt)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.google.testing.platform.launcher.Launcher.main(Launcher.java:149)


Test results saved as file:/var/jenkins_home/workspace/xxxx/app/build/outputs/androidTest-results/connected/S21(AVD)%20-%2012/test-result.pb. Inspect these results in Android Studio by selecting Run > Import Tests From File from the menu bar and importing test-result.pb.
Platform error occurred when running the UTP test suite

FAILURE: Build failed with an exception.

错误信息看起来像是存储空间问题,但是模拟器应该有足够的存储空间。

emulator -avd S21 -memory 2048 -wipe-data -no-boot-anim -cache-size 1000 -noaudio -no-window -partition-size 8192 &

这是设备的创建

avdmanager create avd --force -c 2G -k "system-images;android-32;google_apis;x86_64" -n S21

然后,gradle脚本的调用如下所示:

./gradlew connectedDebugAndroidTest

当我手动构建通用apk时,通过adb安装它,然后运行工具测试,它可以工作,但据我所知,它应该可以在不手动安装应用程序的情况下工作。
出了什么问题?

8cdiaqws

8cdiaqws1#

我在Android 10上切换Git分支时遇到了类似的错误,然后尝试运行一些Instrumentation测试:

Unknown platform error occurred when running the UTP test suite. Please check logs for details.

解决方案是卸载测试APK,然后通过运行UI测试重新安装。步骤如下:

使用电话用户界面:

1.在主屏幕上,按下“应用”按钮或向上轻扫,然后启动“设置”应用。
1.点击“应用和通知”“查看所有应用”或“应用列表”
1.向下滚动列表以找到您的测试APK,该APK通常具有类似"com.company.app.test"的标题,并且具有通用的绿色Android图标。
1.点击此测试APK →卸载→确定。
1.现在运行UI测试。Android Studio将重新安装全新版本的测试APK。

在命令行上使用adb:

# Replace "com.company.app.test" with your APK test package ID
adb uninstall com.company.app.test
xn1cxnb4

xn1cxnb42#

我找到了一个解决方案。问题是模拟器需要很长时间才能启动,所以仪器测试失败,因为它无法在模拟器启动时安装APK
Message: Failed to install APKs: UNKNOWN
我修改了Detect when Android emulator is fully booted中的注解中的解决方案,以延迟后续步骤,直到模拟器完全引导:

emulator -avd S21 -memory 2048 -wipe-data -no-boot-anim -cache-size 1000 -noaudio -no-window -partition-size 8192 &

adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
li9yvcax

li9yvcax3#

在我的例子中,我的模拟器空间不足,显然“测试apk”文件在安装之前就被放置在模拟器中,测试完成后它们就留在那里,所以我不得不删除这些文件,然后它又工作了。

cqoc49vn

cqoc49vn4#

此错误可能有以下原因:
(1)android gradle插件版本与gradle版本不兼容
(2)如果使用无线调试,请尝试使用USB调试

相关问题