Hybrid [iOS-with-ReactNative] Redefinition of module 'DatadogCore'
Describe the issue
We have react-native project and ios project in a seperate repo. iOS already exsists and we have newly created RN repo - All RN code resides in this repo.
iOS app is the main app in which very few screens are based on react-native. These two are integrated using bundle and other.
In iOS repo - DataDog RUM is already instrumented and working fine. In react-native repo - Newly instrumented datadogRUM by installing below
"@datadog/mobile-react-native": "^2.3.5",
"@datadog/mobile-react-native-navigation": "^2.3.5",
"@datadog/mobile-react-navigation": "^2.3.5",
Now in iOS repo, we run pod install and opened Xcode
bundle exec pod install
open AttendeeApp.xcworkspace
Issue -
In xocde when building the App, we are getting below error and build is failed. Redefinition of module 'DatadogCore' Redefinition of module 'DatadogRUM' Redefinition of module 'DatadogLogs' Redefinition of module 'DatadogTrace'
Any help pls ?
Thanks
Reproduction steps
In iOS repo - DataDog RUM is already instrumented and working fine. In react-native repo - Newly instrumented datadogRUM by installing below
"@datadog/mobile-react-native": "^2.3.5",
"@datadog/mobile-react-native-navigation": "^2.3.5",
"@datadog/mobile-react-navigation": "^2.3.5",
Now in iOS repo, we run pod install and opened Xcode
bundle exec pod install
open AttendeeApp.xcworkspace
SDK logs
No response
Device Information
No response
SDK version
"@datadog/mobile-react-native": "^2.3.5"
Integration Methods
NPM
React Native Version
^0.73.4
Package.json Contents
In react-native repo, part of package.json is
"dependencies": { "@datadog/mobile-react-native": "^2.3.5", "@datadog/mobile-react-native-navigation": "^2.3.5", "@datadog/mobile-react-navigation": "^2.3.5", "@types/react-native": "^0.73.0", "react": "18.2.0", "react-native": "^0.73.4", "react-native-code-push": "^8.2.1", }
iOS Setup
In pod file, included
pod 'DatadogSDKObjc', '~> 2.5.0'
Android Setup
No response
Other relevant information
No response
Hello @kesavarao-EB 👋 thank you for reaching out!
I believe the errors are caused by two different versions of the iOS Datadog SDK being installed on the same project.
React Native SDK v2.3.5 is shipped with iOS v2.7.1.
I would try to update the iOS pod to exactly v2.7.1 and see if the issues are resolved, by updating your podfile:
pod 'DatadogSDKObjc', '2.5.0'
Thankyou for checking @marco-saia-datadog
yes i have updated podfile
pod 'DatadogSDKObjc', '2.7.1'
and executed the below
bundle exec pod install
open AttendeeApp.xcworkspace
But still the same error i see in the simulator. Build is failing
@marco-saia-datadog Why we need to added pod 'DatadogSDKObjc', '2.7.1' in iOS repo when We already have defined "@datadog/mobile-react-native": "^2.3.5", in react-native repo ?
The dependency has to be added in order to use the iOS SDK functionalities from your iOS layer.
Please:
- Double check that
2.7.1is also the version you see innode_modules/@datadog/mobile-react-native/DatadogSDKReactNative.podspec - Clean-up iOS project (
cd ios && rm -rf Pods && rm Podfile.lock && pod install --repo-update) - Re-build your project and try again
@marco-saia-datadog I tried in the new setup, still the same error
yes , version is 2.7.1 in node_modules/@datadog/mobile-react-native/DatadogSDKReactNative.podspec
Also executed these steps
- Clean-up iOS project (cd ios && rm -rf Pods && rm Podfile.lock && pod install --repo-update)
- Re-build your project and try again
Would you mind confirming if any steps are missing in this doc (Native app with RN screens) which i am following https://github.com/DataDog/dd-sdk-reactnative/blob/main/docs/hybrid_applications.md#:~:text=Native%20apps%20with%20React%20Native%20screens%3A%20Initialize%20the%20SDK%20on%20the%20native%20side
Also in the example repo, i dont see addition of this line in podfile
pod 'DatadogSDKObjc', '2.5.0'
https://github.com/DataDog/dd-sdk-reactnative-examples/blob/931ce96fde92cb3093c518049450ff81850550ef/ios-app-with-rn/ios/Podfile
Any help on this ?
@kesavarao-EB thank you for your patience 🙏
I believe our documentation might be outdated, we will verify that the instructions are still relevant to this day.
In the meantime, have you tried removing the pod from your Podfile?
If you can access Datadog SDK classes from your codebase, without manually adding the pod to your Podfile, the setup is correct and the SDK will function properly.
@marco-saia-datadog Still the same. In the clean setup just added the following
Step 1) iOS Repo :
yarn add @datadog/mobile-react-native
Clarification : I doubt if this will be required. Because we already have DataDog iOS sdk installed . After running @datadog/mobile-react-native and pod installing will install the below.
Installing DatadogCore 2.7.1
Installing DatadogCrashReporting (2.7.1)
Installing DatadogInternal 2.7.1
Installing DatadogLogs 2.7.1
Installing DatadogRUM 2.7.1
Installing DatadogSDKReactNative
Installing DatadogTrace 2.7.1
Installing DatadogWebViewTracking
Installing PLCrashReporter
This may have possibility to get conflict with the exsiting DatadogCore and other which got installed with DataDogiOS-sdk.
Step 2 - cd to ios
bundle exec pod install
open AttendeeApp.xcworkspace
Still the same issue. Sorry, is this working in your environment . Or am i missing any steps ?
Can you provide the working steps ?
If I understand correctly, you have Datadog iOS SDK installed in your native project already.
Have you checked that the native version of the iOS SDK matches the version defined in node_modules/@datadog/mobile-react-native/DatadogSDKReactNative.podspec?
If it does, and you encounter the same issue, you might then have to patch the SDK, with our support.
This issue could be currently blocking https://github.com/DataDog/dd-sdk-reactnative/issues/682.
Both has same version 2.7.1 Still can see same error. Can you confirm if this example project is working ? https://github.com/DataDog/dd-sdk-reactnative-examples/tree/931ce96fde92cb3093c518049450ff81850550ef/ios-app-with-rn as we have closely followed this for initialization.
@kesavarao-EB I am updating the example project and verifying that everything is working properly. I will get back to you soon!
hello! @marco-saia-datadog and @kesavarao-EB we are under the same situation and same project structure: native app with the Native Datadog SDK, and with react native screens wanting to use the React Native Datadog SDK. We get the exact same "duplicate modules" error after adding the @datadog/mobile-react-native dependency in the native repository, even after matching the SDK versions (2.30.0). Is there any fix for this? I also tried following the docs for hybrid apps, and also the PR with the update to the sample app, but something seems off. For instance, there are no matching DatadogSDKObjc versions for the latest React Native Datadog SDK version (2.30.0).
By the way, the native repository is using SPM to get the native datadog sdk but we have our app to also use CocoaPods for the react native setup.
Any help here on how to setup a hybrid app would be appreciated.
Hi @nico-gonzalez sorry for the delay.
We recently updated our sample app showcasing a native iOS app integrating some RN views, so perhaps the new code can give you a clearer example of how that would look.
With that said, I'm positive that this specific problem can be due to the fact that you are using SPM to include the native Datadog SDK instead of relying in the Pod already included by the RN SDk. In any case, I'm going to try to reproduce the problem on our sample app and will come back to you shortly.
Also, and for reference, this is a correlation of the native versions of the SDK that should be used with each version of the RN SDK: https://github.com/DataDog/dd-sdk-reactnative/blob/develop/NATIVE_SDK_VERSIONS.md
Hello again @nico-gonzalez.
Indeed I can confirm that adding the native Datadog SDK via SPM as well as adding it via Cocoapods through RN causes this issue (duplicated symbols).
In future versions of the SDK we will move away from Cocoapods and will deliver the native SDK via SPM. However, this is only compatible with RN 0.75+ (more info: https://github.com/facebook/react-native/pull/44627)
In the meantime, I'm afraid that the only real and robust solution to this is to rely on React Native to import the Native SDK via Cocoapods and stop importing it via SPM.
Thanks @sbarrio for taking a look into this. Due to the nature of our hybrid React Native and native app we cannot rely 100% on getting the SDK using Cocoapods so we will wait until we can use SPM
Hello again @nico-gonzalez.
Indeed I can confirm that adding the native Datadog SDK via SPM as well as adding it via Cocoapods through RN causes this issue (duplicated symbols).
In future versions of the SDK we will move away from Cocoapods and will deliver the native SDK via SPM. However, this is only compatible with RN 0.75+ (more info: https://github.com/facebook/react-native/pull/44627)
In the meantime, I'm afraid that the only real and robust solution to this is to rely on React Native to import the Native SDK via Cocoapods and stop importing it via SPM.
Hi @nico-gonzalez 👋 If there's anything else we can help with in the meantime, please let us know. Otherwise, I'll go ahead and close this issue for now, but feel free to open a new one or re-open this if needed.