dd-sdk-reactnative
dd-sdk-reactnative copied to clipboard
Android issue: null is not an object (evaluating 'this.nativeRum.startView')
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:

Steps to reproduce the issue:
- tested with a Pixel 4 emulator with API 28 (Android 9.0), and a Galaxy S20 Ultra emulator with API 30 (Android 11.0)
Describe what you expected:
Additional context
- Version of the SDK
- @datadog/[email protected]
- @datadog/[email protected]
- A copy of your package.json file:
- Note: I have ejected from expo
{
"name": "",
"scripts": {},
"dependencies": {
"@datadog/mobile-react-native": "^1.0.0-rc4",
"@datadog/mobile-react-navigation": "^1.0.0-rc4",
"@expo/vector-icons": "^12.0.0",
"@ptomasroos/react-native-multi-slider": "^2.2.2",
"@react-native-async-storage/async-storage": "^1.13.2",
"@react-native-community/cli-platform-ios": "^4.13.0",
"@react-native-community/cookies": "^5.0.1",
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/bottom-tabs": "^6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/stack": "^6.0.11",
"@unimodules/core": "~6.0.0",
"@unimodules/react-native-adapter": "~5.7.0",
"bcrypt": "^3.0.6",
"blinkid-react-native": "^5.8.1",
"expo": "^40.0.0",
"expo-asset": "~8.2.1",
"expo-constants": "~9.3.3",
"expo-facebook": "~9.1.0",
"expo-file-system": "~9.3.0",
"expo-font": "~8.4.0",
"expo-linear-gradient": "~8.4.0",
"install": "^0.13.0",
"lodash": "^4.17.15",
"npm": "^8.3.0",
"payment-icons": "^1.2.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "0.63.4",
"react-native-code-push": "^6.2.1",
"react-native-datepicker": "^1.7.2",
"react-native-dotenv": "^2.5.1",
"react-native-elements": "^1.2.7",
"react-native-firebase": "^5.6.0",
"react-native-gesture-handler": "~1.8.0",
"react-native-google-places-autocomplete": "^2.1.2",
"react-native-indicators": "^0.17.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-onesignal": "^4.0.1",
"react-native-picker-select": "^6.5.0",
"react-native-reanimated": "^1.7.0",
"react-native-rn-apple-pay-button": "github:brascene/rn-apple-pay-button",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.10.1",
"react-native-sectioned-multi-select": "^0.8.1",
"react-native-unimodules": "~0.12.0",
"react-native-vector-icons": "^6.6.0",
"react-native-video": "^5.0.0",
"react-native-web": "~0.13.12",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
"tipsi-stripe": "^9.1.1"
},
"devDependencies": {
"@babel/core": "~7.9.0",
"@babel/runtime": "^7.8.4",
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"babel-jest": "~24.9.0",
"babel-preset-expo": "8.3.0",
"jest": "~24.9.0",
"jetifier": "~1.6.4",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "~16.13.1",
"typescript": "^4.5.4"
},
"private": true
}
Any help is appreciated!
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:
- Delete
node_modulesfolder and do clean install - Delete Gradle build cache folder and do clean install (you can simply manually delete
android/app/buildfolder) - Check that Android native modules are recognized by the RN tooling by running by running
npx react-native configfrom the root of your app. It should be an entry there like that:
"@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.
DdSdkReactNative.initializereturns aPromise. Do you see any error oncePromiseis resolved?- Are you able to send logs with
DdLogsand see then in theLogssection of our dashboard?
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.
@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?
@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.
@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.
@john-harding Can you please show the initialization logic? Do you see any relevant warnings during the build or at the runtime?
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);
});
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?
In my case
ERROR [TypeError: null is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "./foundation").DdSdk.initialize')]
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.
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).
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"
}
}
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",
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
Thanks @govarthananve, It solved my crash!.
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.
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
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.
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.
@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?
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!
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)
}
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.
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 -ato clear all the javascript and android caches and see if it works.
@louiszawadzki it works! you fixed my problem <3 thanks!