adobe / aepsdk-react-native

A wrapper around the iOS and Android AEP mobile SDK to allow for integration with React Native applications.
Apache License 2.0
15 stars 28 forks source link

Error: Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules #247

Closed JoeM-RP closed 1 year ago

JoeM-RP commented 1 year ago

While attempting to add the AEPCore SDK to my iOS app, I encountered an issue preventing the code from compiling.

Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules

Expected Behaviour

After adding AEPCore SDk and running pod install, the app should build and run successfully on iOS

Actual Behaviour

During build phase, the following error causes the build to fail: Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules

Reproduce Scenario (including but not limited to)

Create a new React Native app using Expo: npx create-expo-app my-app

Install AEPCore SDK via npm: npm install @adobe/react-native-aepcore

"Prebuild" to expose iOS folder: expo prebuild --platform ios

Ensure pods installed via: cd ios && pod install

Add imports to AppDelegate.h and implementation to AppDelegate didFinishLaunchingWithOptions per README

Build and run the project via expo run:ios or via XCode

Build fails

Platform and Version

Issue occurs only for iOS. Android integration works as expected

"@adobe/react-native-aepcore": "^1.0.0",
"expo": "~47.0.12",
"react": "18.1.0",
"react-native": "0.70.5",

Sample Code that illustrates the problem

Sample attached: adobe-sample-expo-react-native.zip

mattrace commented 1 year ago

Having this same issue as well. Any help on this would be great!

JoeM-RP commented 1 year ago

Okay, so as a workaround I discovered I can create a separate header file and an objective-c file to wrap the Adobe SDK setup, then import it into the main AppDelegate....

AdobeBridge.h:

#import <Foundation/Foundation.h>

@interface AdobeBridge : NSObject

+ (void)configureAnalytics;

@end

AdobeBridge.m:

#import "AdobeBridge.h"

@import AEPCore;

@implementation AdobeBridge

+ (void)configureAnalytics
{
  [AEPMobileCore configureWithAppId:@"app_id_here"];
}

@end

And in AppDelegate.mm:

  [super application:application didFinishLaunchingWithOptions:launchOptions];

  [AdobeBridge configureAnalytics];

  return YES;

Very strange that a direct reference does work for a vanilla react native project, but this extra step is required for react native with expo. This method works, but I would love to figure out why the normal process isn't suitable here

Working sample: adobe-sample-expo-reac-native-working.zip

yangyansong-adbe commented 1 year ago

@JoeM-RP
It looks like the issue only happened on the expo project. Unfortunately, we don't support building our packages with expo for now. Really glad to see that the issue is resolved, and thank you for sharing your analysis.

Thanks, Yansong

BashirTowdiee commented 1 year ago

Hey, This issue is not expo specific, as it also happens on react-native Bare. It's a native compiler error.

You can try enabling the @import directive for .mm(Objective-C++) files.

In Xcode

xcode_flags

@JoeM-RP I do like your workaround with separate files!👌 Helps keeps AppDelegate.mm cleaner.

sdubey01 commented 5 months ago

@JoeM-RP - I took your approach for a RN 72 Expo SDK 49 bare app and am running into issues getting other extensions to register.

This approach is still giving me errors when I include the remaining code required to set up the AEP extensions

" const UIApplicationState appState = application.applicationState; [AEPMobileCore registerExtensions:@[ AEPMobileLifecycle.class, AEPMobileIdentity.class, AEPMobileEdgeIdentity.class, AEPMobileEdge.class, AEPMobileEdgeBridge.class, ] completion:^{ if (appState != UIApplicationStateBackground) { [AEPMobileCore lifecycleStart:nil]; } }];"

I get an error stating "Undefined symbols for architecture x86_64: "_OBJCCLASS$_AdobeBridge", referenced from: in AppDelegate.old: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)"

I have added the above code to your AdobeBridge.m file assuming it more or less takes the place of any code that Adobe recommends be placed into the AppDelegate.mm file.

Have you set up any AEP libraries/extensions like this other than the base Mobile Core? I specifically need to configure Edge Bridge because we use Analytics trackState and trackActions.

JoeM-RP commented 5 months ago

@sdubey01 - at a glance, everything seems to line up. Here's a gist with the complete files for all three major pieces within iOS: https://gist.github.com/JoeM-RP/271758305aaa5d92a6d435cd85452994

...and our abbreviated package.json:

"dependencies": {
    "@adobe/react-native-aepassurance": "^5.0.0",
    "@adobe/react-native-aepcampaignclassic": "^5.0.0",
    "@adobe/react-native-aepcore": "^5.0.1",
    "@adobe/react-native-aepedge": "^5.0.0",
    "@adobe/react-native-aepedgeconsent": "^5.0.0",
    "@adobe/react-native-aepedgeidentity": "^5.0.0",
    "@adobe/react-native-aepoptimize": "^5.0.0",
    "@adobe/react-native-aepplaces": "^5.0.2",
    "@adobe/react-native-aeptarget": "^5.0.0",
    "@adobe/react-native-aepuserprofile": "^5.0.0",
    "@expo/dev-server": "0.1.120",
    "@expo/react-native-action-sheet": "^4.0.0",
    "@expo/vector-icons": "^13.0.0",
    "@expo/webpack-config": "^19.0.0",
    "expo": "^49.0.16",
    "expo-application": "~5.3.0",
    "expo-asset": "~8.10.1",
    "expo-av": "~13.4.1",
    "expo-build-properties": "~0.8.3",
    "expo-constants": "~14.4.2",
    "expo-device": "~5.4.0",
    "expo-font": "~11.4.0",
    "expo-insights": "~0.2.0",
    "expo-linear-gradient": "~12.3.0",
    "expo-linking": "~5.0.2",
    "expo-local-authentication": "~13.4.1",
    "expo-localization": "~14.3.0",
    "expo-network": "~5.4.0",
    "expo-notifications": "~0.20.1",
    "expo-screen-orientation": "~6.0.6",
    "expo-secure-store": "~12.3.1",
    "expo-sharing": "~11.5.0",
    "expo-splash-screen": "~0.20.5",
    "expo-system-ui": "~2.4.0",
    "expo-updates": "~0.18.19",
    "expo-web-browser": "~12.3.2",
    "react": "18.2.0",
    "react-native": "0.72.6",
  }

I'm not actively working with the product anymore, but maybe there's a conflict with a recent XCode update?

sdubey01 commented 5 months ago

Sadly my files match yours and it still fails. I'm on an M1 macbook, so possible the issue is there. Also possible that your suspicion of an Xcode update is to blame if you last had it working before Xcode 15.4. - Looks like I will table this attempt and try to get us upgraded to RN 73 Expo SDK 50 with the newest Adobe libraries (some are up to V 6.x now) ... maybe the Expo libs that prevent the official Adobe fix of adding in the -fcxx-modules build flag have been resolved.