killserver / react-native-screenshot-prevent

MIT License
104 stars 39 forks source link

`new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method. [Android] #55

Open ArturBuja opened 2 weeks ago

ArturBuja commented 2 weeks ago

Hello: RN info:

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M2
  Memory: 85.55 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.9.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.yarn/bin/yarn
  npm:
    version: 10.8.3
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.09.30.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/lib/ruby/gems/3.3.0/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 3.3.5
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 14.1.1
    wanted: ^14.1.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.4
    wanted: 0.75.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

"react-native-screenshot-prevent": "^1.2.1",

Code example:

  useEffect(() => {
    if (Platform.OS === 'android') {
      RNScreenshotPrevent.enabled(true);

      return () => {
        RNScreenshotPrevent.enabled(false);
      };
    }
    if (Platform.OS === 'ios') {
      RNScreenshotPrevent.enableSecureView();
      return () => {
        RNScreenshotPrevent.disableSecureView();
      };
    }
  }, []);

I got the error: `new NativeEventEmitter() was called with a non-null argument without the required addListener method.` When I started the app. The code above doesn't even run then I got the following error.

RVassili commented 5 days ago

Can you check your native logs for the root error ?

ArturBuja commented 5 days ago

What do you mean native error? I get this error right away at the start of the application. I can possibly send a screenshot of the error. Or you mean log from logcat?

RVassili commented 4 days ago

I mean, this is most likely an error from the javascript part of your application, and you most likely have an error from the native part (kotlin or java) part, connect to a native debugger an check if you have any native error

ArturBuja commented 4 days ago

I mean, this is most likely an error from the javascript part of your application, and you most likely have an error from the native part (kotlin or java) part, connect to a native debugger an check if you have any native error

This error start appear when I added the code above, and if I remove these piece of code the error disappears, but I'll check the native errors

ArturBuja commented 4 days ago

I run RN Debbuget and in the console I can see:

image

But its nothing new, at 19 there is an import RNScreenshotPrevent from 'react-native-screenshot-prevent';

I honestly don't know how to debug this more precisely. I also run a logcat in Android Studio but there is nothing special about this message.

RVassili commented 4 days ago

Can you share your logcat ?

ArturBuja commented 4 days ago

ok, from fresh start: https://drive.google.com/file/d/117TLKMSKHvGsT-nSUJ4c61vA2x9sLNc6/view?usp=sharing

RVassili commented 4 days ago

I see nothing obvious sadly sorry :( We used to have similar issues when using this lib with codepush, do you have some lib that might restart your app ?

ArturBuja commented 4 days ago

My app works fine, there is no restart in the app just the error. In my package.json there is nothing special


    "@adrianso/react-native-device-brightness": "^1.2.7",
    "@eabdullazyanov/react-native-sms-user-consent": "^1.2.0",
    "@notifee/react-native": "^9.1.1",
    "@react-native-async-storage/async-storage": "^2.1.0",
    "@react-native-community/netinfo": "^11.4.1",
    "@react-native-firebase/app": "^21.0.0",
    "@react-native-firebase/messaging": "^21.0.0",
    "@react-navigation/material-top-tabs": "^6.6.14",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "@reduxjs/toolkit": "^2.2.8",
    "@sentry/react-native": "^5.34.0",
    "axios": "^1.7.7",
    "bwip-js": "^4.5.1",
    "core-js": "^3.38.1",
    "dotenv": "^16.4.5",
    "i18next": "^23.15.2",
    "i18next-chained-backend": "^4.6.2",
    "i18next-http-backend": "^2.6.2",
    "i18next-resources-to-backend": "^1.2.1",
    "intl-pluralrules": "^2.0.1",
    "jwt-decode": "^4.0.0",
    "libphonenumber-js": "1.10.59",
    "nativewind": "^2.0.11",
    "ncp": "^2.0.0",
    "react": "18.3.1",
    "react-i18next": "^15.0.2",
    "react-native": "0.75.4",
    "react-native-bootsplash": "^6.2.2",
    "react-native-config": "^1.5.3",
    "react-native-contacts": "^7.0.8",
    "react-native-country-codes-picker": "^2.3.5",
    "react-native-date-picker": "^5.0.7",
    "react-native-device-info": "^13.0.0",
    "react-native-devsettings": "^1.0.5",
    "react-native-encrypted-storage": "^4.0.3",
    "react-native-fast-image": "^8.6.3",
    "react-native-flash-message": "^0.4.2",
    "react-native-modal": "^13.0.1",
    "react-native-otp-entry": "^1.7.2",
    "react-native-pager-view": "^6.4.1",
    "react-native-permissions": "^4.1.5",
    "react-native-safe-area-context": "^4.11.0",
    "react-native-screens": "^3.34.0",
    "react-native-screenshot-prevent": "^1.2.1",
    "react-native-sim-cards-manager": "^1.0.24",
    "react-native-size-matters": "^0.4.2",
    "react-native-svg": "^15.7.1",
    "react-native-tab-view": "^3.5.2",
    "react-native-vision-camera": "^4.6.0",
    "react-redux": "^9.1.2",
    "react-zlib-js": "^1.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/cli": "^14.1.1",
    "@react-native/babel-preset": "0.75.4",
    "@react-native/eslint-config": "0.75.4",
    "@react-native/metro-config": "0.75.4",
    "@react-native/typescript-config": "0.75.4",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "husky": "^9.1.6",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-native-svg-transformer": "^1.5.0",
    "react-test-renderer": "18.3.1",
    "tailwindcss": "3.3.2",
    "typescript": "5.0.4"
  },