Skip to content

Commit

Permalink
android: Build RN from source, at our fork, for targetSdkVersion 34
Browse files Browse the repository at this point in the history
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:
  #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.
  • Loading branch information
chrisbobbe authored and gnprice committed Sep 28, 2024
1 parent 382e31f commit 0509575
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 298 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ dependencies {

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

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

Expand Down
12 changes: 12 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ buildscript {
// What's the latest? Consult this list:
// https://developer.android.com/studio/releases/platforms
compileSdkVersion = 34

// Latest NDK 24, for Apple Silicon compatibility.
ndkVersion = "24.0.8215888"
}
repositories {
google()
Expand Down Expand Up @@ -61,6 +64,15 @@ allprojects {
mavenCentral()
google()
}

configurations.all {
resolutionStrategy {
dependencySubstitution {
// Make our dependencies look at our RN fork built from source.
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
}
}
}
}

subprojects {
Expand Down
16 changes: 16 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenLocal()
google()
}
}

rootProject.name = 'ZulipMobile'

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

include ':app'

include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')

// The RN Gradle Plugin is needed to build RN from source.
// (We do that to make some changes to RN, with our zulip/react-native fork.)
includeBuild('../node_modules/react-native/packages/react-native-gradle-plugin')
24 changes: 24 additions & 0 deletions docs/howto/forked-rn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Using a `react-native` with cherry-picked or custom changes

Since 2024-09, we use a fork of `react-native` to make changes
atop 0.68.7. We prefer to avoid upgrading to later `react-native`
releases because it's laborious and we're eager to retire this
codebase and transition to `zulip-flutter`.

When there's an issue in React Native that calls for changes in
React Native:

- Push those changes to our RN fork, `zulip/react-native`,
on the `0.68.7-zulip` branch.

- Update the `package.json`:

```json
"react-native": "zulip/react-native#<commit-id>",
```

- Run `yarn`.

When building for Android, it will take longer the first time because
React Native is built from source. (`react-native` releases on NPM,
which we've been using until recently, come with a pre-built binary.)
190 changes: 0 additions & 190 deletions docs/howto/rn-from-git.md

This file was deleted.

2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ SPEC CHECKSUMS:
EXScreenOrientation: e3c072fb0add472a3037482ea43ccbade9b88a25
EXSQLite: 2b9accd925438293f9f39e0a57a08cca13bdffb2
FBLazyVector: 63b89dc85804d5817261f56dc4cfb43a9b6d57f5
FBReactNativeSpec: 1fa200a9862d9369a53b6fddbbfcdc22bab24062
FBReactNativeSpec: de66c1e28c6823a30a53b51dd933560edb24ed3f
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 476ee3e89abb49e07f822b48323c51c57124b572
RCT-Folly: 4d8508a426467c48885f1151029bc15fa5d7b3b8
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lodash.uniq": "^4.5.0",
"react": "17.0.2",
"react-intl": "5.24.6",
"react-native": "0.68.7",
"react-native": "zulip/react-native#b7b2f6c22",
"react-native-document-picker": "^8.1.3",
"react-native-gesture-handler": "^2.8.0",
"react-native-image-picker": "^5.3.1",
Expand Down
102 changes: 0 additions & 102 deletions patches/react-native+0.68.7.patch

This file was deleted.

Loading

0 comments on commit 0509575

Please sign in to comment.