We started using JSpecify nullness annotations inside Robolectric. You may see new warnings
regarding non-nullable or potentatial null pointer exception.
ConscryptMode is now ON on every platform (it was OFF on Mac arm64).
Deprecations
Deprecated symbol
Replacement
org.robolectric:shadows-httpclient
N/A
SQLiteMode
SQLiteMode.Mode.NATIVE is now the default, and usages of these APIs can be removed-
SQLiteModeConfigurer
SQLiteMode.Mode.NATIVE is now the default, and usages of these APIs can be removed-
Removals
Removed symbol
Replacement
AndroidVersionInitTools
N/A
AndroidVersions
Build.VERSION_CODES.* and VersionCalculator
Implements#callThroughByDefault(boolean)
N/A
Implements#looseSignatures(boolean)
@ClassName or Implementation#methodName(String)
Migrating to 4.16
Breaking Changes
Drop support for API 21 and 22. Robolectric now supports API 23 (M) up to 36 (Baklava).
Deprecations
Deprecated symbol
Replacement
TextLayoutMode
TextLayoutMode.Mode.REALISTIC is the default, and usages of these APIs can be removed.
TextLayoutModeConfigurer
TextLayoutMode.Mode.REALISTIC is the default, and usages of these APIs can be removed.
Removals
Removed symbol
Replacement
org.robolectric:shadows-playservices
Use APIs provided by Google Play Services libraries
The following attributes of the @Config annotation are no longer supported when
using binary resources mode:
assetDir and resourceDir: follow
the recommended file structure of your build system.
manifest: Robolectric always uses the merged manifest generated by
the Android toolchain. If your test was using a custom manifest you'll need to adapt it to not
rely on that.
packageName: to change your package name, override the
applicationId in your build system.
Improper Use of Shadows
Prior to Robolectric 4.0, it was possible (but ill-advised) to get the shadow for an Android
framework object and invoke framework methods there. This could result in unexpected behavior (e.g.,
code in overridden methods in subclasses wouldn't be called). Shadow implementation methods are now
marked protected to guard against this. Always invoke framework methods directly on the Android
class.
Robolectric 4.0 includes initial support for androidx.test APIs. We strongly
recommend adding the latest version of androidx.test:core as a test dependency and using those
APIs whenever possible rather than using Robolectric-specific APIs.
Robolectric 4.0 replaces its old home-grown resource handling code with a direct adaptation of
Android's resource handling code, using the full Android toolchain. This greatly improves fidelity
to the behavior of a real Android device, but if your tests were relying on the quirks of the old
code, you may need to fix your tests.
Some likely issues include:
android.view.InflateException: Binary XML file line #3: Failed to resolve attribute at index
17: TypedValue{t=0x2/d=0x7f01000e a=-1}
This happens when your Activity is using a theme that lacks values
for certain attributes used by layouts. Make sure you've specified an appropriate theme for your
activities in your AndroidManifest.