Skip to content

Commit 1ca75eb

Browse files
Abbondanzofacebook-github-bot
authored andcommitted
Remove obsolete Android SDK compatibility shims
Summary: Use `Build.VERSION_CODES` and the framework window attribute directly for APIs available in the current compile SDK, removing obsolete numeric compatibility shims. Retain only the Android 17 version shim, which is newer than the internal compile SDK. Remove a stale `DisplayMetrics` dependency that pulled edge-to-edge window code into unrelated consumers. Changelog: [Internal] Differential Revision: D122209144
1 parent ed2d531 commit 1ca75eb

3 files changed

Lines changed: 13 additions & 42 deletions

File tree

‎packages/react-native/ReactAndroid/build.gradle.kts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,9 @@ android {
584584
minSdk = libs.versions.minSdk.get().toInt()
585585

586586
aarMetadata {
587-
// RN's public ABI exposes no android API newer than 34, and the source is written to
588-
// compile against SDK 34 (see util/AndroidVersion.kt). compileSdk is 36 only to build
589-
// against the latest platform — it is not an API requirement. Without this, AGP 9
590-
// defaults minCompileSdk to compileSdk (36), needlessly forcing every consuming
591-
// library/app to compileSdk 36.
587+
// RN's public ABI exposes no Android API newer than 34, so consumers do not need to
588+
// match ReactAndroid's compile SDK. Without this, AGP 9 defaults minCompileSdk to
589+
// compileSdk, needlessly forcing every consuming library/app to use the same SDK.
592590
minCompileSdk = 34
593591
}
594592

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/util/AndroidVersion.kt‎

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,18 @@ import android.os.Build
1414
internal object AndroidVersion {
1515

1616
/**
17-
* This is the version code for Android 15 (SDK Level 35). Internally at Meta this code is also
18-
* compiled against SDK 34, so we need to retain this constant instead of using
19-
* [Build.VERSION_CODES.VANILLA_ICE_CREAM] directly.
20-
*/
21-
internal const val VERSION_CODE_VANILLA_ICE_CREAM: Int = 35
22-
23-
/**
24-
* This is the version code for Android 16 (SDK Level 36). Internally at Meta this code is also
25-
* compiled against SDK 34, so we need to retain this constant instead of using
26-
* [Build.VERSION_CODES.BAKLAVA] directly.
27-
*/
28-
internal const val VERSION_CODE_BAKLAVA: Int = 36
29-
30-
/**
31-
* This is the version code for Android 17 (SDK Level 37). Internally at Meta this code is also
32-
* compiled against SDK 34, so we need to retain this constant instead of using
17+
* This is the version code for Android 17 (SDK Level 37). Internally at Meta this code is
18+
* compiled against SDK 36, so we need to retain this constant instead of using
3319
* [Build.VERSION_CODES.CINNAMON_BUN] directly.
3420
*/
3521
internal const val VERSION_CODE_CINNAMON_BUN: Int = 37
3622

37-
/**
38-
* android.R.attr.windowOptOutEdgeToEdgeEnforcement added in API 35. Internally at Meta this code
39-
* is compiled against an SDK that may not have this attribute defined.
40-
* https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/res/res/values/public-final.xml;l=3848
41-
*/
42-
internal const val ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT: Int = 0x0101069a
43-
44-
/**
45-
* This method is used to check if the current device is running Android 15 (SDK Level 35) or
46-
* higher and the app is targeting Android 15 (SDK Level 35) or higher.
47-
*/
48-
@JvmStatic
49-
internal fun isAtLeastTargetSdk35(context: Context): Boolean =
50-
Build.VERSION.SDK_INT >= VERSION_CODE_VANILLA_ICE_CREAM &&
51-
context.applicationInfo.targetSdkVersion >= VERSION_CODE_VANILLA_ICE_CREAM
52-
5323
/**
5424
* This method is used to check if the current device is running Android 16 (SDK Level 36) or
5525
* higher and the app is targeting Android 16 (SDK Level 36) or higher.
5626
*/
5727
@JvmStatic
5828
fun isAtLeastTargetSdk36(context: Context): Boolean =
59-
Build.VERSION.SDK_INT >= VERSION_CODE_BAKLAVA &&
60-
context.applicationInfo.targetSdkVersion >= VERSION_CODE_BAKLAVA
29+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA &&
30+
context.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.BAKLAVA
6131
}

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ public fun setEdgeToEdgeFeatureFlagOn() {
4545
internal fun updateEdgeToEdgeFeatureFlag(activity: Activity) {
4646
// When the app targets SDK 35+, edge-to-edge may be enforced by the OS even if the
4747
// feature flag wasn't explicitly set. In that case, turn the flag on to match.
48-
if (AndroidVersion.isAtLeastTargetSdk35(activity)) {
49-
if (Build.VERSION.SDK_INT >= AndroidVersion.VERSION_CODE_BAKLAVA) {
48+
if (
49+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
50+
activity.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.VANILLA_ICE_CREAM
51+
) {
52+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {
5053
// The device is running Android 16+ (where edge-to-edge is always enforced)
5154
isEdgeToEdgeFeatureFlagOn = true
5255
} else {
53-
val attributes = intArrayOf(AndroidVersion.ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT)
56+
val attributes = intArrayOf(android.R.attr.windowOptOutEdgeToEdgeEnforcement)
5457
val typedArray = activity.theme.obtainStyledAttributes(attributes)
5558

5659
// The device is running Android 15 with / without opting out

0 commit comments

Comments
 (0)