DataDog / dd-sdk-reactnative

Datadog SDK for ReactNative
Apache License 2.0
118 stars 41 forks source link

Android issue: null is not an object (evaluating 'this.nativeRum.startView') #137

Open john-harding opened 2 years ago

john-harding commented 2 years ago

Describe what happened Include any error message or stack trace if available.

Everything works on iOS, and data comes through to my DataDog dashboard. When attempting to run on Android emulators I receive this error after the app successfully installs and opens: null is not an object (evaluating 'this.nativeRum.startView'). It points to the file foundation.tsx and line 50.

I also tried clearing all caches multiple times.

Here is the stack trace:

Screen Shot 2022-01-04 at 3 01 55 AM

Steps to reproduce the issue:

Describe what you expected:

Additional context

Any help is appreciated!

0xnm commented 2 years ago

Hello @john-harding! Thanks for opening this issue.

By looking on the error it seems that native Android modules are not loaded. I would suggest doing the following:

    "@datadog/mobile-react-native": {
      "root": ".....",
      "name": "@datadog/mobile-react-native",
      "platforms": {
        "ios": {
          "sourceDir": "....",
          "folder": "....",
          "pbxprojPath": "....",
          "podfile": null,
          "podspecPath": "....",
          "projectPath": "....",
          "projectName": "DdSdkReactNative.xcodeproj",
          "libraryFolder": "Libraries",
          "sharedLibraries": [],
          "plist": [],
          "scriptPhases": [],
          "configurations": []
        },
        "android": {
          "sourceDir": "....",
          "folder": ".....",
          "packageImportPath": "import com.datadog.reactnative.DdSdkReactNativePackage;",
          "packageInstance": "new DdSdkReactNativePackage()",
          "buildTypes": []
        }
      },
      "assets": [],
      "hooks": {},
      "params": []
    }

You should have some values in the android node group.

john-harding commented 2 years ago

Thanks @0xnm. Your mention of DdSdkReactNative.initialize made me realize that DdRumReactNavigationTracking.startTrackingViews() may have been running before the initialize had completed. Waiting for that promise to finish fixed the issue. I'm surprised I had no issues with iOS.

john-harding commented 2 years ago

@0xnm so actually I'm still having issues. DdSdkReactNative.initialize(config) is returning null is not an object (evaluating '_foundation.DdSdk.initialize'). Didn't catch this earlier because it was in a try/catch statement with no logging in the catch.

I tried all of the other items you listed as well. Do you have any other ideas?

0xnm commented 2 years ago

@john-harding Do you see a package declared in the @datadog/mobile-react-native > platforms > android > packageInstance when you run npx react-native config? At what point do you call initialize?

Also you can check the setup in our sample app for the reference.

john-harding commented 2 years ago

@0xnm yep I see "packageInstance": "new DdSdkReactNativePackage()". I call initialize in the constructor of the class that holds the entire app. I wouldn't think that's the issue though, as it works in iOS and responds as though the native module isn't there at all.

0xnm commented 2 years ago

@john-harding Can you please show the initialization logic? Do you see any relevant warnings during the build or at the runtime?

secure12 commented 2 years ago

I face the same problem: error [TypeError: null is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "./foundation").DdSdk.initialize')]

The initialization is exactly the same as the sample on dd console:

import {
  DdSdkReactNative,
  DdSdkReactNativeConfiguration,
} from '@datadog/mobile-react-native';

const config = new DdSdkReactNativeConfiguration(
  'something',
  'DEBUG',
  'something',
  true, // track User interactions (e.g.: Tap on buttons. You can use 'accessibilityLabel' element property to give tap action the name, otherwise element type will be reported)
  true, // track XHR Resources
  true, // track Errors
);
// Optional: Select your Datadog website (one of "US", "EU" or "GOV")
config.site = 'US';
// Optional: enable or disable native crash reports
config.nativeCrashReportEnabled = true;
// Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
config.sampleRate = 80;

DdSdkReactNative.initialize(config)
  .then(() => {
    console.log('works');
  })
  .catch(err => {
    console.log('error', err);
  });
0xnm commented 2 years ago

Hello @secure12! Can you please check the steps described here https://github.com/DataDog/dd-sdk-reactnative/issues/137#issuecomment-1004660281? In your case is _$$_REQUIRE(_dependencyMap[5], "./foundation") equal to null or _$$_REQUIRE(_dependencyMap[5], "./foundation").DdSdk?

cavaalex commented 2 years ago

In my case

 ERROR  [TypeError: null is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "./foundation").DdSdk.initialize')]
GiladR1979 commented 2 years ago

This is still an issue for me. The initialization fails because DdSdkReactNative is undefined, only happens on Android. EDIT: Its actually in DdRumReactNavigationTracking.tsx, when running DdSdk.initialize. DdSdk is undefined.

0xnm commented 2 years ago

Hello @cavaalex and @GiladR1979! Can you please post your package.json and try the steps described in the following comment.

If you also can share a reproducible example, it would be great (we also have a sample app to check).

AlexandreLage commented 2 years ago

I am sorry @0xnm We had to disable datadog on our next android build.

I had tried to comment you mentioned. No success.

Our dependencies are the following:

{
 "dependencies": {
    "@babel/polyfill": "^7.2.5",
    "@babel/preset-flow": "^7.13.13",
    "@bugsnag/react-native": "^7.3.0",
    "@datadog/mobile-react-native": "^1.0.0-rc4",
    "@hookform/resolvers": "^2.8.8",
    "@react-native-async-storage/async-storage": "^1.15.5",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-native-firebase/analytics": "^11.5.0",
    "@react-native-firebase/app": "^11.5.0",
    "@react-native-firebase/messaging": "^11.5.0",
    "@react-native-picker/picker": "^1.16.8",
    "buffer": "5.2.1",
    "color": "^3.1.0",
    "compare-versions": "^3.6.0",
    "fast-memoize": "^2.5.1",
    "formik": "^1.3.1",
    "hermes-engine": "^0.7.2",
    "jwt-decode": "^2.2.0",
    "libphonenumber-js": "^1.7.8",
    "lodash": "^4.17.21",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.23",
    "node-polyglot": "^2.3.0",
    "phoenix-socket": "^1.2.3",
    "promise-timeout": "^1.3.0",
    "react": "17.0.1",
    "react-native": "0.64.1",
    "react-native-adjust": "^4.29.5",
    "react-native-appboy-sdk": "^1.28.0",
    "react-native-barcode-builder": "^2.0.0",
    "react-native-device-info": "^8.1.3",
    "react-native-exception-handler": "^2.10.10",
    "react-native-fs": "^2.18.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-get-random-values": "^1.7.0",
    "react-native-haptic-feedback": "^1.11.0",
    "react-native-maps": "^0.28.0",
    "react-native-permissions": "^3.0.3",
    "react-native-rate": "^1.2.6",
    "react-native-restart": "^0.0.22",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^2.15.2",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.1",
    "react-native-tracking-transparency": "^0.1.1",
    "react-native-video": "^5.1.1",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",
    "react-redux": "^7.2.4",
    "redux": "^4.1.0",
    "redux-saga": "^1.1.3",
    "reselect": "^4.0.0",
    "route-parser": "^0.0.5",
    "tipsi-stripe": "^9.0.0",
    "url-search-params-polyfill": "^5.0.0",
    "uuid": "^8.3.2",
    "whatwg-url": "7.0.0",
    "yup": "^0.32.9"
  }
}
govarthananve commented 2 years ago

Till facing this below issue in android [TypeError: null is not an object (evaluating '_$$_REQUIRE(_dependencyMap[7], "./foundation").DdSdk.initialize')]

"@datadog/mobile-react-native": "^1.0.0-rc5",
"@datadog/mobile-react-navigation": "^1.0.0-rc5",
govarthananve commented 2 years ago

After adding mannuelly below import in MainApplication.java this issue got resolved import com.datadog.reactnative.DdSdkReactNativePackage;

protected List<ReactPackage> getPackages() {
                    return Arrays.<ReactPackage>asList(
                    ....
                    new DdSdkReactNativePackage()
                    .....
                    )
                    }

example/android/app/src/main/java/com/example/ddsdkreactnative/MainApplication.java

Now working fine for me

GiladR1979 commented 2 years ago

Thanks @govarthananve, It solved my crash!.

0xnm commented 2 years ago

Hello @govarthananve! This is a very useful information. Can you please tell which version of React Native you are using and if you are using Expo - its version as well. This will help us to understand better why native modules are not loaded.

govarthananve commented 2 years ago

Hello @govarthananve! This is a very useful information. Can you please tell which version of React Native you are using and if you are using Expo - its version as well. This will help us to understand better why native modules are not loaded.

React native : 0.64.2 No Expo

GiladR1979 commented 2 years ago

Hello @govarthananve! This is a very useful information. Can you please tell which version of React Native you are using and if you are using Expo - its version as well. This will help us to understand better why native modules are not loaded.

For me- react-native 0.63.3, no Expo.

louiszawadzki commented 2 years ago

Hi everyone,

To add to @govarthananve's answer, if you get an error like:

error: package com.datadog.reactnative does not exist

when trying to add import com.datadog.reactnative.DdSdkReactNativePackage;, you may need to run yarn react-native link @datadog/mobile-react-native to link the package properly.

MattFoley commented 1 year ago

@louiszawadzki My project has auto linking disabled on Android as we have a pretty complicated/custom implementation. Do you have any documentation on how to manually link in on Android? For us, this usually means pointing at a .jar, or pointing to an .aar hosted on some repository, as we can't include locally built .aars. I'm getting this error because of the native Android files not being pulled into the project. Do you have a hosted .jar or .aar somewhere?

louiszawadzki commented 1 year ago

Hi @MattFoley, thanks for reaching out!

I think your issue will require a bit of back-and-forth between us, would you mind opening a new dedicated feature request issue so we can keep the 2 discussions separate? Also could you include an example of a react-native package that do have hosted .jar or .aar, and how you would include it in your app? That will help us to get started on this faster :)

Thank you very much!

chiaraturbati commented 1 year ago

Hi,I have the same error, do you have any other suggestion?

ERROR [TypeError: null is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "./foundation").DdSdk.initialize')]

"@datadog/mobile-react-native": "^1.3.0",
"react-native": "0.70.4",
 compileSdkVersion = 31

I've done @govarthananve solution, I've also tried to follow @0xnm and this is my npx react-native config:

 ` "@datadog/mobile-react-native": {
  "root": "...",
  "name": "@datadog/mobile-react-native",
  "platforms": {
    "ios": {
      ...},
    "android": {
      "sourceDir": "...",
      "packageImportPath": "import com.datadog.reactnative.DdSdkReactNativePackage;",
      "packageInstance": "new DdSdkReactNativePackage()",
      "buildTypes": [],
      "componentDescriptors": [],
      "androidMkPath": "...",
      "cmakeListsPath": "..."
    }
  }
},

I call the initialize in ComponentDidMount of App.tsx

 const datadogConfig = new DdSdkReactNativeConfiguration(
      'my-code',
      'test',
      'my-code',
      true, // track User interactions (e.g.: Tap on buttons. You can use 'accessibilityLabel' element property to give tap action the name, otherwise element type will be reported)
      !__DEV__, // track XHR Resources
      !__DEV__ // track Errors
    )
    // Optional: Select your Datadog website (one of "US", "EU" or "GOV")
    datadogConfig.site = 'EU'
    // Optional: enable or disable native crash reports
    datadogConfig.nativeCrashReportEnabled = true
    // Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
    datadogConfig.sessionSamplingRate = 100
try {
  await DdSdkReactNative.initialize(datadogConfig)
} catch (error) {
  console.warn('Error initializing Datadog SDK: ', error)
}
louiszawadzki commented 1 year ago

Hi @chiaraturbati, thanks for reaching out!

This is unfortunately a long standing issue that we have a hard time reproducing. I found this issue on the React Native repo suggesting to turn on the Debug mode for your app (which should open a Google Chrome tab) as a fix.

Could you try it and see if it works?

If this does not fix the issue, you can run npx rn-game-over -j -a to clear all the javascript and android caches and see if it works.

chiaraturbati commented 1 year ago

Hi @chiaraturbati, thanks for reaching out!

This is unfortunately a long standing issue that we have a hard time reproducing. I found this issue on the React Native repo suggesting to turn on the Debug mode for your app (which should open a Google Chrome tab) as a fix.

Could you try it and see if it works?

If this does not fix the issue, you can run npx rn-game-over -j -a to clear all the javascript and android caches and see if it works.

@louiszawadzki it works! you fixed my problem <3 thanks!