Skip to content

Commit f849c85

Browse files
authored
fix: Android TurboModule compatibility with RN 0.80 (#15)
Fixes a TurboModule compatibility issue for Android. Starting from RN 0.80, `isBlockingSynchronousMethod = true` annotated methods can't be `void` and they must return a value. Fixes: GetStream/stream-video-js#1858 As part of this PR, we are also upgrading the sample apps to RN 0.80.1 and enabling `new architecture` by default for them. Ref: https://github.com/facebook/react-native/blob/v0.80.1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleInteropUtils.kt#L59
1 parent 49c2455 commit f849c85

File tree

28 files changed

+5938
-1433
lines changed

28 files changed

+5938
-1433
lines changed

.github/workflows/android_ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
android-compile:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- uses: actions/setup-java@v4
1818
with:
1919
distribution: 'temurin'
2020
java-version: '17'
21-
- uses: actions/setup-node@v3
21+
- uses: actions/setup-node@v4
2222
with:
23-
node-version: '16.x'
23+
node-version: '22.x'
2424
cache: 'npm'
2525
cache-dependency-path: '**/package-lock.json'
2626

2727
- name: Install node modules
2828
run: npm install
29-
29+
3030
- name: Install example node modules
3131
run: npm install
3232
working-directory: ./examples/GumTestApp/

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
name: Lint
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-node@v3
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
1212
with:
13-
node-version: 16
13+
node-version: 22
1414
- run: npm install
1515
- name: Check if the git repository is clean
1616
run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1)

.github/workflows/ios_ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ jobs:
1313
ios-compile:
1414
runs-on: macos-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717

18-
- uses: actions/setup-node@v3
18+
- uses: actions/setup-node@v4
1919
with:
20-
node-version: '16.x'
20+
node-version: '22.x'
2121
cache: 'npm'
2222
cache-dependency-path: '**/package-lock.json'
2323

2424
- name: Cache cocoapods
25-
uses: actions/cache@v3
25+
uses: actions/cache@v4
2626
with:
2727
path: ./examples/GumTestApp/ios/Pods
2828
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18
1+
v22

android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public void transceiverSetDirection(int id, String senderId, String direction, P
715715
}
716716

717717
@ReactMethod(isBlockingSynchronousMethod = true)
718-
public void transceiverSetCodecPreferences(int id, String senderId, ReadableArray codecPreferences) {
718+
public boolean transceiverSetCodecPreferences(int id, String senderId, ReadableArray codecPreferences) {
719719
ThreadUtils.runOnExecutor(() -> {
720720
WritableMap identifier = Arguments.createMap();
721721
WritableMap params = Arguments.createMap();
@@ -774,6 +774,7 @@ public void transceiverSetCodecPreferences(int id, String senderId, ReadableArra
774774
Log.d(TAG, "transceiverSetCodecPreferences(): " + e.getMessage());
775775
}
776776
});
777+
return true;
777778
}
778779

779780
@ReactMethod
@@ -1313,7 +1314,7 @@ public void peerConnectionAddICECandidate(int pcId, ReadableMap candidateMap, Pr
13131314
candidateMap.hasKey("sdpMid") && !candidateMap.isNull("sdpMid") ? candidateMap.getString("sdpMid") : "",
13141315
candidateMap.hasKey("sdpMLineIndex") && !candidateMap.isNull("sdpMLineIndex") ? candidateMap.getInt("sdpMLineIndex") : 0,
13151316
candidateMap.getString("candidate"));
1316-
1317+
13171318
peerConnection.addIceCandidate(candidate, new AddIceObserver() {
13181319
@Override
13191320
public void onAddSuccess() {

examples/GumTestApp/App.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
* https://github.com/facebook/react-native
44
*
55
* @format
6-
* @flow strict-local
76
*/
8-
97
import React, {useState} from 'react';
108
import {
119
Button,
@@ -14,18 +12,15 @@ import {
1412
View,
1513
StatusBar,
1614
} from 'react-native';
17-
import { Colors } from 'react-native/Libraries/NewAppScreen';
1815
import { mediaDevices, RTCView } from '@stream-io/react-native-webrtc';
1916

20-
2117
const App = () => {
2218
const [stream, setStream] = useState(null);
2319
const start = async () => {
2420
console.log('start');
2521
if (!stream) {
2622
try {
2723
const s = await mediaDevices.getUserMedia({ video: true });
28-
2924
setStream(s);
3025
} catch(e) {
3126
console.error(e);
@@ -79,14 +74,14 @@ const App = () => {
7974

8075
const styles = StyleSheet.create({
8176
body: {
82-
backgroundColor: Colors.white,
77+
backgroundColor: '#fff',
8378
...StyleSheet.absoluteFill
8479
},
8580
stream: {
8681
flex: 1
8782
},
8883
footer: {
89-
backgroundColor: Colors.lighter,
84+
backgroundColor: '#f8f8f8',
9085
position: 'absolute',
9186
bottom: 0,
9287
left: 0,

examples/GumTestApp/android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def enableProguardInReleaseBuilds = false
6363
* The preferred build flavor of JavaScriptCore (JSC)
6464
*
6565
* For example, to use the international variant, you can use:
66-
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
66+
* `def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'`
6767
*
6868
* The international variant includes ICU i18n library and necessary data
6969
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
7070
* give correct results when using with locales other than en-US. Note that
7171
* this variant is about 6MiB larger per architecture than default.
7272
*/
73-
def jscFlavor = 'org.webkit:android-jsc:+'
73+
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
7474

7575
/**
7676
* Private function to get the list of Native Architectures you want to build.
@@ -126,4 +126,4 @@ dependencies {
126126
} else {
127127
implementation jscFlavor
128128
}
129-
}
129+
}

examples/GumTestApp/android/app/src/main/java/com/gumtestapp/MainApplication.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import android.app.Application
44
import com.facebook.react.PackageList
55
import com.facebook.react.ReactApplication
66
import com.facebook.react.ReactHost
7+
import com.facebook.react.ReactNativeApplicationEntryPoint
78
import com.facebook.react.ReactNativeHost
89
import com.facebook.react.ReactPackage
9-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
1010
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
1111
import com.facebook.react.defaults.DefaultReactNativeHost
12-
import com.facebook.react.soloader.OpenSourceMergedSoMapping
13-
import com.facebook.soloader.SoLoader
1412

1513
class MainApplication : Application(), ReactApplication {
1614

@@ -35,10 +33,6 @@ class MainApplication : Application(), ReactApplication {
3533

3634
override fun onCreate() {
3735
super.onCreate()
38-
SoLoader.init(this, OpenSourceMergedSoMapping)
39-
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
40-
// If you opted-in for the New Architecture, we load the native entry point for this app.
41-
load()
42-
}
36+
ReactNativeApplicationEntryPoint.loadReactNative(this);
4337
}
4438
}

examples/GumTestApp/android/build.gradle

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ buildscript {
55
buildToolsVersion = "35.0.0"
66
minSdkVersion = 24
77
compileSdkVersion = 35
8-
targetSdkVersion = 34
9-
10-
ndkVersion = "26.1.10909125"
11-
ndkVersion = "23.1.7779620"
12-
kotlinVersion = "1.9.24"
8+
targetSdkVersion = 35
9+
ndkVersion = "27.1.12297006"
10+
kotlinVersion = "2.1.20"
1311
}
1412
repositories {
1513
google()
@@ -28,4 +26,4 @@ allprojects {
2826
}
2927
}
3028

31-
apply plugin: "com.facebook.react.rootproject"
29+
apply plugin: "com.facebook.react.rootproject"

examples/GumTestApp/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
3232
# your application. You should enable this flag either if you want
3333
# to write custom TurboModules/Fabric components OR use libraries that
3434
# are providing them.
35-
newArchEnabled=false
35+
newArchEnabled=true
3636

3737
# Use this property to enable or disable the Hermes JS engine.
3838
# If set to false, you will be using JSC instead.

0 commit comments

Comments
 (0)