Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceEventEmitter not working in release version of the app #48424

Closed
shriyash-joinroy opened this issue Jan 2, 2025 · 2 comments
Closed

DeviceEventEmitter not working in release version of the app #48424

shriyash-joinroy opened this issue Jan 2, 2025 · 2 comments
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.

Comments

@shriyash-joinroy
Copy link

Description

DeviceEventEmitter.addListener is not working in release version, but works completely fine in the debug version of the app.
When added a adblogcat command to observe the event emission from the native code, we can see that data is emitted from the native side of the app, but fails to capture in react side.

Steps to reproduce

  1. Add useEffect in the app.js file to listen for the event.
    useEffect(function() {
    let deferredLinkSubscription = null

    // Adding event listener to handle deferred links
    if (Platform.OS === 'android') {
    deferredLinkSubscription = DeviceEventEmitter.addListener(
    'InstallReferrer',
    function(data) {
    handleDeferredLinkUrl(data)
    }
    )
    }

    return () => {
    // Clean up the event listeners on unmount
    deferredLinkSubscription?.remove?.()
    }
    }, [])

React Native Version

0.76.5

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: Windows 11 10.0.26100
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
  Memory: 1.38 GB / 15.69 GB
Binaries:
  Node:
    version: 20.10.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.8.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "28"
      - "31"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-33 | Google APIs Intel x86_64 Atom
      - android-33 | Google Play Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
      - android-34 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-242.23339.11.2421.12550806
  Visual Studio: Not Found
Languages:
  Java: 17.0.8
  Ruby:
    version: 3.3.5
    path: C:\tools\ruby33\bin\ruby.EXE
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.5
    wanted: 0.76.5
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

12-30 23:12:50.002   559   602 I ActivityManager: Start proc 24555:com.android.vending/u0a131 for service {com.android.vending/com.google.android.finsky.externalreferrer.GetInstallReferrerService}
12-30 23:16:49.935 25681 25681 I InstallReferrer: Emitted value: false
12-30 23:16:51.084 25681 25782 D InstallReferrerState: OK
12-30 23:16:51.127 25681 25793 I InstallReferrer: Referrer: darius_taylor
12-30 23:16:51.148 25681 25793 I InstallReferrer: Referrer sent to React Native: darius_taylor

Reproducer

https://github.com/shriyash-joinroy/referrer-api

Screenshots and Videos

No response

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Triage 🔍 labels Jan 2, 2025
@mensonones
Copy link

I downloaded your repository and tested your code. In debug mode, it didn't work (at least not here).
I believe the issue is that React Native hasn't fully initialized the context yet (i.e., ReactContext hasn't been created), so you won't be able to emit the event to JavaScript. This happens when getReactContext() returns null, which means React Native isn't ready to receive events.

It's not much, but I hope I was able to help in some way.

native log that interests you (in debug and before start react context)

2025-01-04 22:18:20.799 25150-25187 InstallReferrer com.reproducerapp I ReactContext not ready. Queuing referrer.
2025-01-04 22:18:20.799 25150-25187 InstallReferrer com.reproducerapp I ReactContextListener added to handle referrer.

@shriyash-joinroy
Copy link
Author

I somehow worked it out using NativeEventEmitter in React Native and adding up the 3s delay on kotlin side to send the referrer argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.
Projects
None yet
Development

No branches or pull requests

3 participants