Some time ago, my instrumented tests stopped working. I get an exception trying to sign the test apk from BouncyCastle. I did a git bisect to find the commit where the tests stopped working. I was able to find where they stopped, and remove what caused them to stop working (it was adding pdfbox, which has a dependency on BouncyCastle). Great, I thought, problem solved. Nope. Removing pdfbox from HEAD doesn't get the tests running again. I could run git bisect again to figure out when the next thing that caused them to break was, but that's really painful, since I'd need to manually remove pdfbox and all the code that uses it at each step.
Note, I can build (and sign) releases and debug apks, just not the tests. I can run junit tests (locally, not on the device). I can run tests with roboelectic. I can even built the test apk, and manually push to the device and run it via adb.
But I cannot run instrumented tests from Android Studio or gradle. I can make a new test project, it runs tests just fine. Sure feels like some dependency in the app broken build system, which is a bit disturbing. I see really old (from 2014-2015) on similar issues, but the solutions don't quite seem to applicable any more.
I found something that suggested adding
android.jetifier.ignorelist=bcprov
to gradle.properties. That sounded promising, but didn't work. Maybe the parameter isn't quite right.
here's the output from ./gradlew connectedDebugAndroidTest --stacktrace
:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:connectedDebugAndroidTest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:147)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:135)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:337)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:324)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:317)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder
at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.<init>(Unknown Source)
at com.android.build.gradle.internal.testing.utp.TLSUtilsKt.createCert(TLSUtils.kt:58)
at com.android.build.gradle.internal.testing.utp.TLSUtilsKt.generateRsaKeyPair(TLSUtils.kt:50)
at com.android.build.gradle.internal.testing.utp.UtpTestResultListenerServerRunner.<init>(UtpTestResultListenerServerRunner.kt:67)
at com.android.build.gradle.internal.testing.utp.UtpTestResultListenerServerRunner.<init>(UtpTestResultListenerServerRunner.kt:35)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt$runUtpTestSuiteAndWait$1.invoke(UtpTestUtils.kt:122)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt$runUtpTestSuiteAndWait$1.invoke(UtpTestUtils.kt:121)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt.runUtpTestSuiteAndWait(UtpTestUtils.kt:136)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt.runUtpTestSuiteAndWait$default(UtpTestUtils.kt:112)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner$1.invoke(UtpTestRunner.kt:55)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner$1.invoke(UtpTestRunner.kt:54)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner.scheduleTests(UtpTestRunner.kt:123)
at com.android.build.gradle.internal.testing.BaseTestRunner.runTests(BaseTestRunner.java:196)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoSuchFieldError: id_alg_hss_lms_hashsig [in thread "Execution worker Thread 8"]
at org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder.<clinit>(Unknown Source)
at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.<init>(Unknown Source)
at com.android.build.gradle.internal.testing.utp.TLSUtilsKt.createCert(TLSUtils.kt:58)
at com.android.build.gradle.internal.testing.utp.TLSUtilsKt.generateRsaKeyPair(TLSUtils.kt:50)
at com.android.build.gradle.internal.testing.utp.UtpTestResultListenerServerRunner.<init>(UtpTestResultListenerServerRunner.kt:67)
at com.android.build.gradle.internal.testing.utp.UtpTestResultListenerServerRunner.<init>(UtpTestResultListenerServerRunner.kt:35)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt$runUtpTestSuiteAndWait$1.invoke(UtpTestUtils.kt:122)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt$runUtpTestSuiteAndWait$1.invoke(UtpTestUtils.kt:121)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt.runUtpTestSuiteAndWait(UtpTestUtils.kt:136)
at com.android.build.gradle.internal.testing.utp.UtpTestUtilsKt.runUtpTestSuiteAndWait$default(UtpTestUtils.kt:112)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner$1.invoke(UtpTestRunner.kt:55)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner$1.invoke(UtpTestRunner.kt:54)
at com.android.build.gradle.internal.testing.utp.UtpTestRunner.scheduleTests(UtpTestRunner.kt:123)
at com.android.build.gradle.internal.testing.BaseTestRunner.runTests(BaseTestRunner.java:196)
at com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask.lambda$doTaskAction$2(DeviceProviderInstrumentTestTask.java:376)
at com.android.builder.testing.api.DeviceProvider.use(DeviceProvider.java:55)
at com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask.doTaskAction(DeviceProviderInstrumentTestTask.java:364)
at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(BaseTask.kt:66)
at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:51)
at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:97)
at jdk.internal.reflect.GeneratedMethodAccessor2048.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:248)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:233)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:216)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:199)
at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:166)