Skip to content

Commit ed990d8

Browse files
committed
android: Build RN from source, at our fork, for targetSdkVersion 34
This gets us zulip/react-native@5c36f102f and its fixup commit zulip/react-native@b7b2f6c22 (on the `0.68.7-zulip` branch), to fix a build failure with `targetSdkVersion = 34` without having to upgrade to RN v0.73. (The build failure is in debug builds only, but we still need to make those to develop fixes in this legacy project as needed.) Thanks to Greg for investigating the build failure: zulip#5877 (comment) Since (as part of working on this) the `0.68.7-zulip` branch also includes the things that were in the patch-package patch, that patch becomes redundant and we delete it here. Done by digesting the history of RN's doc on building RN from source: facebook/react-native-website@22da0cc63 and making some simplifications. The line `ndkVersion = 24…` sets a variable that ReactAndroid reads, to control the NDK version it builds with. It would otherwise build with NDK 21, which is old and chosen automatically based on ReactAndroid's targetSdkVersion of 31. We need it to be at least 24 for Apple Silicon support.
1 parent 07d79c0 commit ed990d8

File tree

9 files changed

+57
-298
lines changed

9 files changed

+57
-298
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ dependencies {
240240

241241
implementation fileTree(dir: "libs", include: ["*.jar"])
242242
//noinspection GradleDynamicVersion
243-
implementation "com.facebook.react:react-native:+" // From node_modules
243+
implementation project(':ReactAndroid')
244244

245245
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
246246

android/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ buildscript {
2020
// What's the latest? Consult this list:
2121
// https://developer.android.com/studio/releases/platforms
2222
compileSdkVersion = 34
23+
24+
// Latest NDK 24, for Apple Silicon compatibility.
25+
ndkVersion = "24.0.8215888"
2326
}
2427
repositories {
2528
google()
@@ -61,6 +64,15 @@ allprojects {
6164
mavenCentral()
6265
google()
6366
}
67+
68+
configurations.all {
69+
resolutionStrategy {
70+
dependencySubstitution {
71+
// Make our dependencies look at our RN fork built from source.
72+
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
73+
}
74+
}
75+
}
6476
}
6577

6678
subprojects {

android/settings.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
mavenLocal()
5+
google()
6+
}
7+
}
8+
19
rootProject.name = 'ZulipMobile'
210

311
apply from: '../node_modules/expo/scripts/autolinking.gradle'
@@ -7,3 +15,11 @@ apply from: file("../node_modules/@react-native-community/cli-platform-android/n
715
applyNativeModulesSettingsGradle(settings)
816

917
include ':app'
18+
19+
include ':ReactAndroid'
20+
project(':ReactAndroid').projectDir = new File(
21+
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
22+
23+
// The RN Gradle Plugin is needed to build RN from source.
24+
// (We do that to make some changes to RN, with our zulip/react-native fork.)
25+
includeBuild('../node_modules/react-native/packages/react-native-gradle-plugin')

docs/howto/forked-rn.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Using a `react-native` with cherry-picked or custom changes
2+
3+
Since 2024-09, we use a fork of `react-native` to make changes
4+
atop 0.68.7. We prefer to avoid upgrading to later `react-native`
5+
releases because it's laborious and we're eager to retire this
6+
codebase and transition to `zulip-flutter`.
7+
8+
When there's an issue in React Native that calls for changes in
9+
React Native:
10+
11+
- Push those changes to our RN fork, `zulip/react-native`,
12+
on the `0.68.7-zulip` branch.
13+
14+
- Update the `package.json`:
15+
16+
```json
17+
"react-native": "zulip/react-native#<commit-id>",
18+
```
19+
20+
- Run `yarn`.
21+
22+
When building for Android, it will take longer the first time because
23+
React Native is built from source. (`react-native` releases on NPM,
24+
which we've been using until recently, come with a pre-built binary.)

docs/howto/rn-from-git.md

Lines changed: 0 additions & 190 deletions
This file was deleted.

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ SPEC CHECKSUMS:
599599
EXScreenOrientation: e3c072fb0add472a3037482ea43ccbade9b88a25
600600
EXSQLite: 2b9accd925438293f9f39e0a57a08cca13bdffb2
601601
FBLazyVector: 63b89dc85804d5817261f56dc4cfb43a9b6d57f5
602-
FBReactNativeSpec: 1fa200a9862d9369a53b6fddbbfcdc22bab24062
602+
FBReactNativeSpec: de66c1e28c6823a30a53b51dd933560edb24ed3f
603603
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
604604
glog: 476ee3e89abb49e07f822b48323c51c57124b572
605605
RCT-Folly: 4d8508a426467c48885f1151029bc15fa5d7b3b8

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"lodash.uniq": "^4.5.0",
5858
"react": "17.0.2",
5959
"react-intl": "5.24.6",
60-
"react-native": "0.68.7",
60+
"react-native": "zulip/react-native#b7b2f6c22",
6161
"react-native-document-picker": "^8.1.3",
6262
"react-native-gesture-handler": "^2.8.0",
6363
"react-native-image-picker": "^5.3.1",

patches/react-native+0.68.7.patch

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)