qtfw
qtfw

Reputation: 31

Android instrumentation test crashes on Firebase Test Lab but runs fine locally

We have recently started adding Espresso instrumentation tests to our app, and I am trying to set up nightly runs of the tests on CircleCI. I got the Circle part working, and the test is getting triggered on Firebase Test Lab as expected, but the test runner is crashing every time with this exception:

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/swing/tree/DefaultTreeCellRenderer;
     FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
Process: [REDACTED], PID: 10933
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/swing/tree/DefaultTreeCellRenderer;
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:453)
    at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:72)
    at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
    at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:793)
    at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:547)
    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:390)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.swing.tree.DefaultTreeCellRenderer" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/[REDACTED]/base.apk", zip file "/data/app/[REDACTED]/base.apk"],nativeLibraryDirectories=[/data/app/[REDACTED]/lib/arm64, /data/app/[REDACTED]/lib/arm64, /data/app/[REDACTED]/base.apk!/lib/arm64-v8a, /data/app/[REDACTED]/base.apk!/lib/arm64-v8a, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 8 more

We did include these in our build.gradle:

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

What could be causing that exception?

I'm getting the same issue when manually using the Firebase Test Lab web GUI in https://console.firebase.google.com/

The tests are running fine locally, both in Android Studio and with adb shell am instrument -w -r -e debug false -e package '[REDACTED]' [REDACTED].debug.test/androidx.test.runner.AndroidJUnitRunner.

Upvotes: 0

Views: 1178

Answers (1)

qtfw
qtfw

Reputation: 31

For our particular case, it was solved by using --environment-variables in the gcloud firebase test android run command, to set the test package (ours is our app package followed by .test) and debug=false. So something like this:

gcloud firebase test android run \
--type instrumentation \
--app [REDACTED].apk \
--test [REDACTED]-androidTest.apk \
--environment-variables package=[REDACTED],debug=false \
--num-flaky-test-attempts 3 \
--device model=blueline,version=28,locale=en_US,orientation=portrait \
--timeout 20m

Upvotes: 1

Related Questions