Increase library target SDK to 31

This only affects the default SDK level that Robolectric tests run at.
Also upgrade the Robolectric version to 4.14.1 to pick up
4f32042afe
which is needed for async `ShadowMediaCodec` support (the default in
ExoPlayer from API 31+).

Some tests fail on Robolectric at API 31. This change configures them to
continue running on API 30, so the failures can be investigated and
fixed in follow-up changes.

PiperOrigin-RevId: 702357124
This commit is contained in:
ibaker 2024-12-03 08:54:51 -08:00 committed by Copybara-Service
parent 148641f049
commit 876abe315b
8 changed files with 20 additions and 7 deletions

View File

@ -20,7 +20,7 @@ project.ext {
appTargetSdkVersion = 34
// Upgrading this requires [Internal ref: b/193254928] to be fixed, or some
// additional robolectric config.
targetSdkVersion = 30
targetSdkVersion = 31
compileSdkVersion = 35
dexmakerVersion = '2.28.3'
// Use the same JUnit version as the Android repo:
@ -33,7 +33,7 @@ project.ext {
kotlinxCoroutinesVersion = '1.8.1'
leakCanaryVersion = '2.10'
mockitoVersion = '3.12.4'
robolectricVersion = '4.11'
robolectricVersion = '4.14.1'
// Keep this in sync with Google's internal Checker Framework version.
checkerframeworkVersion = '3.13.0'
errorProneVersion = '2.18.0'

View File

@ -17,6 +17,7 @@ package androidx.media3.exoplayer;
import static com.google.common.truth.Truth.assertThat;
import android.media.metrics.LogSessionId;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
@ -61,7 +62,8 @@ public class DefaultLoadControlTest {
playerId =
Util.SDK_INT < 31
? new PlayerId(/* playerName= */ "")
: new PlayerId(/* logSessionId= */ null, /* playerName= */ "");
: new PlayerId(
/* logSessionId= */ LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ "");
timeline =
new SinglePeriodTimeline(
/* durationUs= */ 10_000_000L,
@ -128,7 +130,7 @@ public class DefaultLoadControlTest {
/* bufferForPlaybackAfterRebufferMs= */ 0);
build();
// A second player uses the load control.
PlayerId playerId2 = new PlayerId(/* playerName= */ "");
PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ "");
Timeline timeline2 = new FakeTimeline();
MediaSource.MediaPeriodId mediaPeriodId2 =
new MediaSource.MediaPeriodId(
@ -729,7 +731,7 @@ public class DefaultLoadControlTest {
@Test
public void onPrepared_updatesTargetBufferBytes_correctDefaultTargetBufferSize() {
PlayerId playerId2 = new PlayerId(/* playerName= */ "");
PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ "");
loadControl = builder.setAllocator(allocator).build();
loadControl.onPrepared(playerId);
@ -741,7 +743,7 @@ public class DefaultLoadControlTest {
@Test
public void onTrackSelected_updatesTargetBufferBytes_correctTargetBufferSizeFromTrackType() {
PlayerId playerId2 = new PlayerId(/* playerName= */ "");
PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ "");
loadControl = builder.setAllocator(allocator).build();
loadControl.onPrepared(playerId);
loadControl.onPrepared(playerId2);
@ -789,7 +791,7 @@ public class DefaultLoadControlTest {
@Test
public void onRelease_removesLoadingStateOfPlayer() {
PlayerId playerId2 = new PlayerId(/* playerName= */ "");
PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ "");
loadControl = builder.setAllocator(allocator).build();
loadControl.onPrepared(playerId);
loadControl.onPrepared(playerId2);

View File

@ -72,6 +72,7 @@ import org.mockito.junit.MockitoRule;
import org.robolectric.annotation.Config;
/** Unit tests for {@link MediaCodecAudioRenderer} */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+.
@RunWith(AndroidJUnit4.class)
public class MediaCodecAudioRendererTest {
@Rule public final MockitoRule mockito = MockitoJUnit.rule();

View File

@ -41,9 +41,11 @@ import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.GraphicsMode;
/** End-to-end tests for playlists. */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+.
@RunWith(AndroidJUnit4.class)
@GraphicsMode(value = NATIVE)
public final class PlaylistPlaybackTest {

View File

@ -53,8 +53,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.annotation.Config;
/** End-to-end tests using side-loaded WebVTT subtitles. */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+.
@RunWith(ParameterizedRobolectricTestRunner.class)
public class WebvttPlaybackTest {
@ParameterizedRobolectricTestRunner.Parameters(name = "{0}")

View File

@ -93,8 +93,10 @@ import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
/** Unit test for {@link ServerSideAdInsertionMediaSource}. */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+.
@RunWith(AndroidJUnit4.class)
public final class ServerSideAdInsertionMediaSourceTest {

View File

@ -100,11 +100,13 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDisplay;
import org.robolectric.shadows.ShadowLooper;
import org.robolectric.shadows.ShadowSystemClock;
/** Unit test for {@link MediaCodecVideoRenderer}. */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+.
@RunWith(AndroidJUnit4.class)
public class MediaCodecVideoRendererTest {
@Rule public final MockitoRule mockito = MockitoJUnit.rule();

View File

@ -59,8 +59,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.robolectric.annotation.Config;
/** End-to-end tests using HLS samples. */
@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests are non-flaky on API 31+.
@RunWith(AndroidJUnit4.class)
public final class HlsPlaybackTest {