Robolectric android-all runtime jars¶
Robolectric runs each test against an org.robolectric:android-all-instrumented jar for the
test’s SDK level. Left to itself, Robolectric downloads that jar from Maven Central at test time:
one attempt, outside Gradle’s dependency cache and retries, so a single repository blip fails
every Robolectric class at classMethod with AssertionError at MavenArtifactFetcher.java.
How the jars are resolved¶
Every Robolectric module applies automobile.robolectric-sdk-pin, which applies
automobile.robolectric-android-all. That convention:
- Works out the module’s SDK levels from its
src/test*sources. It takes every@Config(sdk = ...)level (Config.OLDEST_SDKcounts as Robolectric’s oldest SDK) and everyrobolectric.propertiessdk=pin. It adds Robolectric’s oldest SDK when there is no primary pin, since that is its default without a manifest. This is a configuration-cacheValueSource, so editing a test’s SDK list invalidates the cached configuration. - Resolves those jars through one non-transitive
robolectricAndroidAll<sdk>configuration per SDK (every jar is a version of the same module, so one configuration would conflict-resolve them down to the newest). They come from Gradle’s dependency cache and its HTTP retries (and, in CI,run-gradle-with-retry.sh). - Writes
build/robolectric/robolectric-deps.properties(writeRobolectricDeps), mapping each jar’sgroup:artifact:versionto its path, and passes it to everyTesttask as-Drobolectric-deps.properties. With that property set Robolectric resolves only from the file and never contacts Maven Central.
The test task tracks the jars by file name, not the properties file, whose absolute paths are machine-specific, so test results stay relocatable in the build cache.
Invariants¶
RobolectricAndroidAlllists the jar version per SDK for one Robolectric release, copied from that release’sDefaultSdkProvider. Configuration fails whenlibs.versions.tomlpins a different Robolectric version, so a Robolectric bump must refresh the table.- An SDK the scan cannot see (for example a
@Configlevel held in a constant other thanConfig.OLDEST_SDK) is missing from the properties file, and Robolectric fails with “no artifacts found” for it. Write SDK levels as numeric literals orBuild.VERSION_CODESnames.