Skip to content

Commit

Permalink
fix(Android): minSdkVersion fallback to default 21 but RN 0.74 requir…
Browse files Browse the repository at this point in the history
…e minSdkVersion 23 (#2346)

## Description
This PR is a potential fix for
[#2295](#2295).
Following suggestions in
[PR#2251](#2251 (comment))
and Android Gradle Plugin version 7.0.0 changes: `minSdkVersion` was
renamed to `minSdk`, `targetSdkVersion` was renamed to `targetSdk`,
`compileSdkVersion` was renamed to `compileSdk`, this PR ensures
compatibility with react native integrated with newest Android projects.

Fixes #2295

<!--
Description and motivation for this PR.

Include Fixes #<number> if this is fixing some issue.

Fixes # .
-->

## Changes
In `adroid/build.gradle` file to get value for `minSdkVersion` in
`defaultConfig` it will look for `minSdkVersion` in rootProject then
look for `minSdk` and then fallback to default. Previously it looked for
`minSdkVersion` and fallback if not found.
Similar logic for `targetSdkVersion` and `compileSdkVersion`
<!--
Please describe things you've changed here, make a **high level**
overview, if change is simple you can omit this section.

For example:

- Updated `about.md` docs

-->

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

<!--
Please include code that can be used to test this change and short
description how this example should work.
This snippet should be as minimal as possible and ready to be pasted
into editor (don't exclude exports or remove "not important" parts of
reproduction example)
-->

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Updated documentation: <!-- For adding new props to native-stack
-->
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
  • Loading branch information
adrianryt authored Sep 25, 2024
1 parent f80281b commit 98d6ca6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ buildscript {
rnsDefaultKotlinVersion = '1.8.0'
}
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
def props = (prop instanceof String) ? [prop] : prop
def result = props.find { key ->
return rootProject.ext.has(key)
}
return result ? rootProject.ext.get(result) : fallback
}
repositories {
google()
Expand Down Expand Up @@ -77,8 +81,8 @@ android {
}

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', rnsDefaultMinSdkVersion)
targetSdkVersion safeExtGet('targetSdkVersion', rnsDefaultTargetSdkVersion)
minSdkVersion safeExtGet(['minSdkVersion', 'minSdk'], rnsDefaultMinSdkVersion)
targetSdkVersion safeExtGet(['targetSdkVersion', 'targetSdk'], rnsDefaultTargetSdkVersion)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", IS_NEW_ARCHITECTURE_ENABLED.toString()
Expand Down Expand Up @@ -136,7 +140,7 @@ android {
}
}
res {
if (safeExtGet('compileSdkVersion', rnsDefaultCompileSdkVersion) >= 33) {
if (safeExtGet(['compileSdkVersion', 'compileSdk'], rnsDefaultCompileSdkVersion) >= 33) {
srcDirs = ["${androidResDir}/base", "${androidResDir}/v33"]
} else {
srcDirs = ["${androidResDir}/base"]
Expand Down

0 comments on commit 98d6ca6

Please sign in to comment.