Skip to content

Commit

Permalink
Fix SDK compat issues in 4.12
Browse files Browse the repository at this point in the history
Update several shadows to use `isInAndroidSdk=false`, which disables
shadowOf method generation. This fixes compile issues for apps that have
compileSdkVersion < Q.
  • Loading branch information
hoisie committed Apr 26, 2024
1 parent e2a8e26 commit fd38419
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions integration_tests/sdkcompat/build.gradle
Expand Up @@ -40,6 +40,7 @@ dependencies {

testImplementation project(":testapp")
testImplementation project(":robolectric")
testImplementation libs.androidx.test.core
testImplementation libs.junit4
testImplementation libs.truth
}
Expand Up @@ -2,10 +2,13 @@

import static com.google.common.truth.Truth.assertThat;

import android.app.Application;
import android.os.Build;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;

/**
* Test class for Java's class resolve compatibility test. We must keep it with Java instead of
Expand All @@ -22,7 +25,7 @@ public void sdkIs29() {
public void shadowOf() {
// https://github.com/robolectric/robolectric/issues/7095
// Enable this assertion when resolving all shadowOf compatibility problem
// assertThat(Shadows.shadowOf((Application) ApplicationProvider.getApplicationContext()))
// .isNotNull();
assertThat(Shadows.shadowOf((Application) ApplicationProvider.getApplicationContext()))
.isNotNull();
}
}
Expand Up @@ -5,7 +5,10 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link android.net.wifi.ScanResult.InformationElement}. */
@Implements(value = ScanResult.InformationElement.class, minSdk = VERSION_CODES.R)
@Implements(
value = ScanResult.InformationElement.class,
minSdk = VERSION_CODES.R,
isInAndroidSdk = false)
public class ShadowInformationElement {
/**
* A builder for creating ShadowInformationElement objects. Use build() to return the
Expand Down
Expand Up @@ -15,6 +15,7 @@
value = PositionedGlyphs.class,
minSdk = S.SDK_INT,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativePositionedGlyphs {
/**
Expand Down
Expand Up @@ -16,6 +16,7 @@
value = RenderEffect.class,
minSdk = O,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeRenderEffect {
static {
Expand Down
Expand Up @@ -22,6 +22,7 @@
value = RuntimeShader.class,
minSdk = O,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeRuntimeShader {

Expand Down
Expand Up @@ -14,6 +14,7 @@
value = TextRunShaper.class,
minSdk = S.SDK_INT,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeTextRunShaper {

Expand Down
Expand Up @@ -11,7 +11,7 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link TranslationManager}. */
@Implements(value = TranslationManager.class, minSdk = VERSION_CODES.S)
@Implements(value = TranslationManager.class, minSdk = VERSION_CODES.S, isInAndroidSdk = false)
public class ShadowTranslationManager {
private final Table<Integer, Integer, ImmutableSet<TranslationCapability>>
onDeviceTranslationCapabilities = HashBasedTable.create();
Expand Down
Expand Up @@ -11,7 +11,7 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link VpnManager}. */
@Implements(value = VpnManager.class, minSdk = VERSION_CODES.R)
@Implements(value = VpnManager.class, minSdk = VERSION_CODES.R, isInAndroidSdk = false)
public class ShadowVpnManager {

private VpnProfileState vpnProfileState;
Expand Down

0 comments on commit fd38419

Please sign in to comment.