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

Use of undeclared identifier 'AEPMobileCore' #346

Open jerry7411 opened 5 months ago

jerry7411 commented 5 months ago

Prerequisites

Bug summary

Hi guys, I'm trying to implement the latest version of AEP SDK . I already followed the guidelines and I got this error

Use of undeclared identifier AEPMobileCore

I cannot use any classes from AEP SDK even though I already imported according to the guidelines image

Environment

Node: 20.12.0 NPM: 10.5.0 Xcode: 15.3 React Native: 0.70.14 React Native AEP SDK: 6.0.0

cacheung commented 5 months ago

@jerry7411, we don't have enough information from you to debug what step was missing in the setup. Have you followed the installation steps?

Some quick guide:

  1. Install packages e.g npm install @adobe/react-native-aepcore

  2. Go to iOS folder to run pod install https://github.com/adobe/aepsdk-react-native?tab=readme-ov-file#ios-development

  3. Initializing SDK https://github.com/adobe/aepsdk-react-native?tab=readme-ov-file#initializing

It should be able to run the app. If you see error, you can look at the troubleshooting and known issues

jerry7411 commented 5 months ago

Hi @cacheung , I already followed exactly the installation steps Maybe Xcode cannot index the AEP classes and interfaces. I'm wondering if it could be related to arm64 and x86_64 architecture?

cacheung commented 5 months ago

Hi @jerry7411 Which architecture you are using to reproduce the issue? What's your Xcode version?

Any error you see other than the undeclared identifier error? Can you attach the logs you see in the Xcode debug window here to show us?

cacheung commented 4 months ago

Hi @jerry7411 , do you have any more info about how to reproduce it?

snowiesuet commented 4 months ago

Hello @cacheung, I'm experiencing this error as well:

Screenshot 2024-05-01 at 3 25 10 PM Screenshot 2024-05-01 at 3 33 05 PM

@jerry7411, we don't have enough information from you to debug what step was missing in the setup. Have you followed the installation steps?

Some quick guide:

1. Install packages
   e.g npm install @adobe/react-native-aepcore

2. Go to iOS folder to run pod install
   https://github.com/adobe/aepsdk-react-native?tab=readme-ov-file#ios-development

3. Initializing SDK
   https://github.com/adobe/aepsdk-react-native?tab=readme-ov-file#initializing

It should be able to run the app. If you see error, you can look at the troubleshooting and known issues

I've followed the steps above and I see the AEM packages in my Pods folder:

Screenshot 2024-05-01 at 3 26 24 PM

imported them in my .h file

Screenshot 2024-05-01 at 3 32 07 PM

I can't figure out what I'm missing and been stuck for days, could you please assist me? Thank you!

Environment: Node: v18.19.1 React-native: 0.70.8 react-native-aepcore: 6.0.1 Xcode: 15.3

cacheung commented 4 months ago

You have an error "Import of C++ module 'Foundation' appears within extern "C" language linkage specification. You might want to fix that first. The libraries can be blocked to import with errors.

Seems like you are using expo? We don't officially support expo. We recommend users to use React Native CLI environment to build with Adobe mobile aepsdk-react-native.
https://reactnative.dev/docs/environment-setup?package-manager=npm&guide=native (React Native CLI)

Our sample app of the AppDelegate.h and AppDelegate.mm files.

If you can provide a sample skeleton package, we can debug it, that would be great.

snowiesuet commented 4 months ago

You're right @cacheung I do think its an issue with expo installer, i created new projects one with Expo and one with React Native Cli and the one with Expo have the same errors as above :(

cacheung commented 4 months ago

@snowiesuet So it works with your React Native Cli setup? We are not official support for Expo due to our sdk has native platforms setup requirement. We will record in our feature request list.

mayank-shekhar commented 4 months ago

Hi, one workaround is that you can try to eject the expo app to get the required ios/android files.

  1. Eject the Expo app.
    npx expo prebuild
  2. Follow the installation steps

You can still run the expo commands to run the app locally.

tr3v3r commented 4 months ago

@cacheung we have completely the same error, but we use Bare React Native and installed the expo module (expo-image). It's not an option for us to get rid of expo module - any suggestions / workarounds?

image
tr3v3r commented 4 months ago

Ok it seems this could help:

https://github.com/adobe/aepsdk-react-native/issues/247#issuecomment-1462326054

cacheung commented 4 months ago

@tr3v3r I haven't got chance to look into the Expo environment closely. Good you found the possible fix. Can you let me know if this solution works after you test it?

tr3v3r commented 4 months ago

@tr3v3r I haven't got chance to look into the Expo environment closely. Good you found the possible fix. Can you let me know if this solution works after you test it?

Yes, that works!

Instead of initializing directly in AppDelegeate, I've created a separate module and call it in AppDelegate.mm:

1) Create files AdobeBridge.h and AdobeBridge.m for your iOS project with the following content:

AdobeBridge.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AdobeBridge : NSObject
+ (void)configure: (UIApplicationState)state;
@end

AdobeBridge.m

#import "AdobeBridge.h"
#import <UIKit/UIKit.h>
@import AEPCore;
@import AEPEdgeIdentity;
@import AEPEdgeConsent;
@import AEPAssurance;
@import AEPEdge;
@import AEPIdentity;
@import AEPLifecycle;
@import AEPSignal;
@import AEPServices;
@import AEPUserProfile;
@import AEPOptimize;
@implementation AdobeBridge
+ (void)configure: (UIApplicationState)appState
{
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
  NSArray *extensionsToRegister = @[
      AEPMobileEdgeIdentity.class,
      AEPMobileEdgeConsent.class,
      AEPMobileAssurance.class,
      AEPMobileEdge.class,
      AEPMobileIdentity.class,
      AEPMobileLifecycle.class,
      AEPMobileOptimize.class,
      AEPMobileSignal.class,
      AEPMobileUserProfile.class
      ];
      [AEPMobileCore registerExtensions:extensionsToRegister completion:^{
        [AEPMobileCore configureWithAppId: @"KEY"];
        if (appState != UIApplicationStateBackground) {
            [AEPMobileCore lifecycleStart:@{@"": @""}];
        }
    }];
}
@end

2) Update AppDelegate.mm as:

#import "AdobeBridge.h" // add this import
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  [AdobeBridge configure: application.applicationState]; // Add this line
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
sdubey01 commented 4 months ago

@tr3v3r I haven't got chance to look into the Expo environment closely. Good you found the possible fix. Can you let me know if this solution works after you test it?

Yes, that works!

Instead of initializing directly in AppDelegeate, I've created a separate module and call it in AppDelegate.mm: ...

Can you clarify if you are running on an M1 (or M2) macbook. I have attempted to get this working in a project that has been upgraded to RN 72 with Expo SDK 49 but keep running into this error "Undefined symbols for architecture x86_64: "_OBJCCLASS$_AdobeBridge", referenced from: in AppDelegate.old: symbol(s) not found for architecture x86_64"

We are a bare RN app with the Expo SDK dependency for a number of native modules and removing the Expo SDK is not an option for us. I need to find a way to get the Adobe code to work with the Expo SDK setups.

tr3v3r commented 4 months ago

Hello @sdubey01,

I use M1 pro max, Xcode 15.3.

It seems you have another problem. My issue was connected with the language conflict between adobe sdk and expo sdk as I understand.

sdubey01 commented 4 months ago

Hello @sdubey01,

I use M1 pro max, Xcode 15.3.

It seems you have another problem. My issue was connected with the language conflict between adobe sdk and expo sdk as I understand.

Thanks for clarifying. It at least rules out the M1 architecture as my issue. I will have to try this approach on the older branch I have for RN 70 or 71 to see if it is an issue with the RN 72/Expo 49 configurations. So frustrating that the 'official response' seems to be 'Expo is not supported' with no real effort to sort out why there is a conflict between the two SDK's. The Expo SDK is widely used for native feature access!

beatlecz commented 3 months ago

We have the same problem with implementing your library into Expo project. We use expo development client, and we are able to integrate almost everything except your library.

sdubey01 commented 3 months ago

@cacheung or @yangyansong-adbe - Can you confirm if there is any official statement of support (or no support) for Bare React Native apps that use the Expo SDK for native integrations (like media files, camera, location access, etc.) ?

I am supporting an app for a large company migrating from the ACP SDK to the AEP SDK and we are having major issues getting iOS to build. Android seems to build and collect analytics as expected but iOS fails. We are not able to use the suggested '-fcxx-modules' build flag because of the Expo SDK. I also have not been successful in getting the suggested 'alternate solution' of using a separate AdobeBridge.h and AdobeBridge.mm to work in this application as others have posted about. Taking this approach leaves me with a new build error referencing "OBJC_CLASS$_AdobeBridge", referenced from: in AppDelegate.old: symbol(s) not found for architecture x86_64"

cacheung commented 3 months ago

@sdubey01 We are not officially supporting Bare React Native apps that use the Expo SDK at this moment. We are currently in the process of evaluating the scope and details of the work required for this support internally.

sainjay commented 3 months ago

@cacheung what's the workaround or setup process for Expo - managed project? I'm on React Native 0.74.2 and Expo - 51.0.11. We have to keep our application updated to the latest version because of the security vulnerability. Can you share the steps for integrating Adobe Analytics in Expo managed project?

cacheung commented 3 months ago

@sainjay There is currently no official workaround for integrating Expo with the Mobile SDK for React Native, some users have reported success with certain steps mentioned in this thread. I recommend exploring those steps to see if they work for your specific use case. Our team is actively evaluating Expo support requirements. If you need further assistance, consider reaching out to Adobe support via a ticket for Expo-related inquiries.

sainjay commented 3 months ago

@tr3v3r I haven't got chance to look into the Expo environment closely. Good you found the possible fix. Can you let me know if this solution works after you test it?

Yes, that works!

Instead of initializing directly in AppDelegeate, I've created a separate module and call it in AppDelegate.mm:

  1. Create files AdobeBridge.h and AdobeBridge.m for your iOS project with the following content:

AdobeBridge.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AdobeBridge : NSObject
+ (void)configure: (UIApplicationState)state;
@end

AdobeBridge.m

#import "AdobeBridge.h"
#import <UIKit/UIKit.h>
@import AEPCore;
@import AEPEdgeIdentity;
@import AEPEdgeConsent;
@import AEPAssurance;
@import AEPEdge;
@import AEPIdentity;
@import AEPLifecycle;
@import AEPSignal;
@import AEPServices;
@import AEPUserProfile;
@import AEPOptimize;
@implementation AdobeBridge
+ (void)configure: (UIApplicationState)appState
{
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
  NSArray *extensionsToRegister = @[
      AEPMobileEdgeIdentity.class,
      AEPMobileEdgeConsent.class,
      AEPMobileAssurance.class,
      AEPMobileEdge.class,
      AEPMobileIdentity.class,
      AEPMobileLifecycle.class,
      AEPMobileOptimize.class,
      AEPMobileSignal.class,
      AEPMobileUserProfile.class
      ];
      [AEPMobileCore registerExtensions:extensionsToRegister completion:^{
        [AEPMobileCore configureWithAppId: @"KEY"];
        if (appState != UIApplicationStateBackground) {
            [AEPMobileCore lifecycleStart:@{@"": @""}];
        }
    }];
}
@end
  1. Update AppDelegate.mm as:
#import "AdobeBridge.h" // add this import
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  [AdobeBridge configure: application.applicationState]; // Add this line
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Tried this in RN 0.74.2 and Expo 51.0.11, facing the following error:

image

Any suggestions on how to get rid of this error?

sainjay commented 3 months ago

For project using Expo 51, RN 0.74, you can use the following configuration:

AppDelegate.h

`

import

import <UIKit/UIKit.h>

// #import <Expo/Expo.h>

import <ExpoModulesCore/EXAppDelegateWrapper.h>

@interface AppDelegate : EXAppDelegateWrapper

@EnD `

AppDelegate.mm

` @import AEPRulesEngine; @import AEPCore; @import AEPLifecycle; @import AEPEdge; @import AEPEdgeIdentity; @import AEPEdgeBridge; @import AEPAssurance; @import AEPSignal;

@implementation AppDelegate

(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { self.moduleName = @"main";

// You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{};

// Initialize Adobe SDK [AEPMobileCore setLogLevel:AEPLogLevelDebug]; [AEPMobileCore configureWithAppId:@"appIDKey"];

const UIApplicationState appState = application.applicationState;

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

return [super application:application didFinishLaunchingWithOptions:launchOptions]; }`

Add the flags as per: https://github.com/adobe/aepsdk-react-native/issues/247#

This works and builds successfully. Android is also building without issues.