adobe/aepsdk-react-native

RCTAEPCore is undefined

Closed this issue · 10 comments

Expected Behaviour

Both Android and IOS device run without error

Actual Behaviour

IOS device runs with error saying that RCTAEPCore is undefined.

Reproduce Scenario (including but not limited to)

Run React Native in IOS device

Steps to Reproduce

react-native: 0.72.6
@adobe/react-native-aepcore: ^5.0.0
Yarn/pnpm

Followed all the steps for IOS and Android documented on the readme.

Platform and Version

Mac M2

Sample Code that illustrates the problem

MobileCore.collectPii({ myPii: 'data' });

Logs taken while reproducing problem

 TypeError: Cannot read property 'collectPii' of null
This error is located at:
    in App
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer

I wonder if there is any configuration for IOS missing on the readme. Thank you very much for your help!

Hi. Yes, I did follow the instructions in the links you sent - added the configurations in both AppDelegate.h and AppDelegate.mm and imported the package the way as you mentioned. I got the error on both M1 and M2 Mac laptops. Meanwhile, I am able to run the sample app without any error.

You need to add import { MobileCore } from '@adobe/react-native-aepcore' to your React Native side of the code, not on the Native platform code.
Similar to the sample app here - https://github.com/adobe/aepsdk-react-native/blob/main/apps/AEPSampleApp/extensions/CoreView.tsx#L15

Did you do that?

Yes, I imported the package in a tsx view file, just like the sample app.

Is it possible to share your sample project, we can take a look?

Sure, that would be really helpful. I created a new repo using react-native-cli (https://github.com/Issactoto/adobe-analytics-test/tree/main). I just changed all the files accordingly as mentioned above and the function is used in App.tsx. I am using Yarn and IOS 17.2 for your information. Thanks!

@Issactoto
When I tried to build the repo you provided in Xcode, I saw errors which can be resolved with these two known workaround:
#247 (comment)
#263 (comment)

 post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    installer.pods_project.targets.each do |t|
      if t.name.start_with?("AEP")
        t.build_configurations.each do |bc|
            bc.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -no-verify-emitted-module-interface'
        end
      end
    end
  end
end

Please give them a try and see if you can build.
These are for iOS.
Did you have the issue on Android?

Thank you very much for the reply and solution. It works for the new repo I shared earlier. However, I am actually using a monorepo for the project I am developing and I am still facing the same error. Unfortunately, I am unable to share the code here. Do you happen to know if there are any specific changes that need to be made in this context? Additionally, I want to note that I don't experience any problems when running the code on Android.

For the original log, we thought it is possible due to the import statement in the react native side.
import { MobileCore } from '@adobe/react-native-aepcore'

This error is located at:
    in App
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer

But it seems like you have that correctly in the sample app you shared.

If using the same react native code and Android platform is working, then the issue is on the iOS side.
Have you tried to run the iOS app from the Xcode and see if there is any other error shown on the Xcode native platform? Or you can monitor the logs in the Xcode debug windows.

Yes, I think there were some errors on the Xcode native platform. I got it sorted now, thank you very much for your help!