android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.16k stars 314 forks source link

UI Tests fail to run with when using play-services-cast:21.3.0 #1831

Open hborders opened 1 year ago

hborders commented 1 year ago

Description

My Android app depends on protobuf-java:3.17.2, and uses espresso:3.5.1 for UI testing. espresso-contrib:3.5.1 depends on com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:3.1.2 depends on com.google.protobuf:protobuf-lite:3.0.1

When I try to run my UI tests, my app immediate crashes with:

java.lang.NoClassDefFoundError: com.google.android.gms.internal.cast.zzrz
at com.google.android.gms.internal.cast.zzth.zza(com.google.android.gms:play-services-cast@@21.3.0:8)
at com.google.android.gms.internal.cast.zztx.zzb(com.google.android.gms:play-services-cast@@21.3.0:3)
at com.google.android.gms.internal.cast.zzsh.zzE(com.google.android.gms:play-services-cast@@21.3.0:1)
at com.google.android.gms.internal.cast.zzse.zzq(com.google.android.gms:play-services-cast@@21.3.0:2)
at com.google.android.gms.internal.cast.zzse.zzp(com.google.android.gms:play-services-cast@@21.3.0:1)
at com.google.android.gms.internal.cast.zzr.zzc(com.google.android.gms:play-services-cast-framework@@21.3.0:7)
at com.google.android.gms.internal.cast.zzq.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at java.lang.Class.forName(Class.java:379)
at com.google.android.gms.internal.cast.zzrz.<clinit>(com.google.android.gms:play-services-cast@@21.3.0:1)
at com.google.android.gms.internal.cast.zzrz.zzb(Unknown Source:0)
at com.google.android.gms.internal.cast.zzth.zza(com.google.android.gms:play-services-cast@@21.3.0:8)
at com.google.android.gms.internal.cast.zztx.zzb(com.google.android.gms:play-services-cast@@21.3.0:3)
at com.google.android.gms.internal.cast.zzsh.zzE(com.google.android.gms:play-services-cast@@21.3.0:1)
at com.google.android.gms.internal.cast.zzse.zzq(com.google.android.gms:play-services-cast@@21.3.0:2)
at com.google.android.gms.internal.cast.zzse.zzp(com.google.android.gms:play-services-cast@@21.3.0:1)
at com.google.android.gms.internal.cast.zzr.zzc(com.google.android.gms:play-services-cast-framework@@21.3.0:7)
at com.google.android.gms.internal.cast.zzq.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at androidx.test.espresso.base.Interrogator.loopAndInterrogate(Interrogator.java:14)
at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:8)
at androidx.test.espresso.base.UiControllerImpl.loopMainThreadUntilIdle(UiControllerImpl.java:16)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:6)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
... 8 more
Caused by: java.lang.IllegalStateException: Unable to lookup extension field offset
at com.google.protobuf.ExtensionSchemaFull.getExtensionsFieldOffset(ExtensionSchemaFull.java:52)
at com.google.protobuf.ExtensionSchemaFull.<clinit>(ExtensionSchemaFull.java:45)
... 28 more

If I remove this dependency with gradle, things seem to work fine:

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module("com.google.protobuf:protobuf-lite") \
            using module("com.google.protobuf:protobuf-java:3.21.12") \
            because "Only espresso-contrib (via accessibility-test-framework) needs protobuf-lite, but everything else needs protobuf-java"
    }
}

Steps to Reproduce

Create a project that uses play-services-cast:21.3.0 and protobuf-java:3.21.12. Then try to run a UI test with espresso-contrib:3.5.1

Expected Results

UI Tests run

Actual Results

App immediately crashes with the above stack trace

AndroidX Test and Android OS Versions

Android API 33. Espresso 3.5.1

Link to a public git repo demonstrating the problem:

hborders commented 1 year ago

I filed a similar issue with the cast team: https://issuetracker.google.com/issues/285919735

I think the root cause here is that com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework should not depend on protobuf-lite because protobuf-lite doesn't guarantee binary compatibility across releases, so any app that uses a different protobuf-lite version (or protobuf-java) might have problems because of this dependency.