mateuscardosogs / react-native-firebase-mlkit

MIT License
89 stars 42 forks source link

Linking issues with manually (no Pods) iOS build #18

Open lake-effect opened 5 years ago

lake-effect commented 5 years ago

I followed the steps in https://github.com/mateusc42/react-native-firebase-mlkit#ios for an iOS manual installation, but when building either from the CLI or in XCode, I get the following error:

CompileC /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.o /Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target: RNMlKit)
    cd /Users/user/project/node_modules/react-native-firebase-mlkit/ios
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/user/project/ios/build/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/user/project/ios/build/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=8.0 -g -Wno-sign-conversion -Winfinite-recursion -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-semicolon-before-method-body -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/user/project/ios/build/Index/DataStore -iquote /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-generated-files.hmap -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-own-target-headers.hmap -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-all-target-headers.hmap -iquote /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-project-headers.hmap -I/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/user/project/React -I../../react-native/React -I../../react-native/React/Base -I../../react-native/React/CxxBridge -I../../react-native/React/CxxModule -I../../react-native/React/CxxUtils -I../../react-native/React/DevSupport -I../../react-native/React/Fabric -I../../react-native/React/Inspector -I../../react-native/React/Modules -I../../react-native/React/Profiler -I../../react-native/React/UIUtils -I../../react-native/React/Views -I../../react-native/React/Base/Surface -I../../react-native/React/Fabric/Mounting -I../../react-native/React/Fabric/Surface -I../../react-native/React/Fabric/Utils -I../../react-native/React/Views/SafeAreaView -I../../react-native/React/Views/ScrollView -I../../react-native/React/Base/Surface/SurfaceHostingView -I../../react-native/React/Fabric/Mounting/ComponentViews -I../../react-native/React/Fabric/Mounting/MountItems -I../../react-native/React/Fabric/Mounting/ComponentViews/ActivityIndicator -I../../react-native/React/Fabric/Mounting/ComponentViews/Image -I../../react-native/React/Fabric/Mounting/ComponentViews/Root -I../../react-native/React/Fabric/Mounting/ComponentViews/ScrollView -I../../react-native/React/Fabric/Mounting/ComponentViews/Switch -I../../react-native/React/Fabric/Mounting/ComponentViews/Text -I../../react-native/React/Fabric/Mounting/ComponentViews/View -I/Users/user/project/ios/Frameworks -I/Users/user/project/ios/Pods/Firebase -I/Users/user/project/ios/Pods/Headers/Public -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/DerivedSources/x86_64 -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/DerivedSources -F/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator -MMD -MT dependencies -MF /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.d --serialize-diagnostics /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.dia -c /Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m -o /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.o

/Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m:6:9: fatal error: 'FirebaseCore/FirebaseCore.h' file not found

#import <FirebaseCore/FirebaseCore.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

libRNFirebase.a is included in the build phases, and react-native itself builds and runs on its own. The error only comes up when I try to add this lib.

Is there a fix that doesn't require cocoapods?

lake-effect commented 5 years ago

One thing that took me further was adding a symlink in ios/Firebase/Analytics/FirebaseCore.framework/Headers/ inside a folder so we have ios/Firebase/Analytics/FirebaseCore.framework/Headers/FirebaseCore/FirebaseCore.h (alias).

At this point the build failure is:

/Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m:7:9: fatal error: 'FirebaseMLVision/FirebaseMLVision.h' file not found
#import <FirebaseMLVision/FirebaseMLVision.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lake-effect commented 5 years ago

If you manually include the Firebase SDK in the project_root/ios/Firebase folder and create the above symlinks, adding the framework-included search path to RNMlKit's xcode project config is sufficient to resolve the first issue:

58B511F11A9E6C8500147676 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                HEADER_SEARCH_PATHS = (
                                        "$(inherited)",
                                        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
                                        "$(SRCROOT)/../../../React/**",
                                        "$(SRCROOT)/../../react-native/React/**",
                                        "$(PROJECT_DIR)/../../../ios/Frameworks/**",
                                        "$(PROJECT_DIR)/../../../ios/Firebase/**",
                                        "$(PROJECT_DIR)/../../../ios/Firebase/Analytics/FirebaseCore.framework/Headers/**",
                                );
lake-effect commented 5 years ago

After following the above steps to get all the headers included, the symbol architectures don't line up at link time:

ProcessProductPackaging "" /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Project.app.xcent (in target: Project)
    cd /Users/user/project/ios

Entitlements:

{
    "com.apple.security.get-task-allow" = 1;
}

    builtin-productPackagingUtility -entitlements -format xml -o /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Project.app.xcent

ProcessProductPackaging "" /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Project.app-Simulated.xcent (in target: Project)
    cd /Users/user/project/ios

Entitlements:

{
    "application-identifier" = "9YGM8KGP3S.com.Project";
    "aps-environment" = development;
}

    builtin-productPackagingUtility -entitlements -format xml -o /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Project.app-Simulated.xcent

Ld /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/Project.app/Project normal x86_64 (in target: Project)
    cd /Users/user/project/ios
    export IPHONEOS_DEPLOYMENT_TARGET=10.0
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk -L/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator -L/Users/user/project/ios -F/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator -F/Users/user/project/ios/Firebase/Analytics -F/Users/user/project/ios/Firebase/InAppMessaging -F/Users/user/project/ios/Firebase/Messaging -filelist /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Objects-normal/x86_64/Project.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=10.0 -Xlinker -object_path_lto -Xlinker /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Objects-normal/x86_64/Project_lto.o -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -ObjC -lc++ -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Project.app-Simulated.xcent -framework MessageUI -framework Social /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTCameraRoll.a -framework Protobuf -framework FirebaseMessaging -framework FirebaseInAppMessaging -framework FirebaseCoreDiagnostics -framework FirebaseCore -framework FirebaseAnalytics -framework GoogleAppMeasurement -framework FIRAnalyticsConnector -framework nanopb -framework FirebaseInstanceID -framework GoogleUtilities /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libReactNativeNavigation.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTBlob.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTAnimation.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libReact.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTAnimation.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTActionSheet.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTGeolocation.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTImage.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTLinking.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTNetwork.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTSettings.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTText.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTVibration.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRCTWebSocket.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libReactNativeCameraKit.a /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRNFetchBlob.a -lRNVectorIcons -lBVLinearGradient -lRNSensitiveInfo /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/libRNDeviceInfo.a -lRNFirebase -lReactNativeFingerprintScanner -lRNCamera -lReactNativeConfig -lRCTVideo -lRNViewShot -lRNShare -lFastImage -lRNMlKit -Xlinker -dependency_info -Xlinker /Users/user/project/ios/build/Build/Intermediates.noindex/Project.build/Debug-iphonesimulator/Project.build/Objects-normal/x86_64/Project_dependency_info.dat -o /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/Project.app/Project

Undefined symbols for architecture x86_64:

  "_OBJC_CLASS_$_FIRVision", referenced from:

      objc-class-ref in libRNMlKit.a(RNMlKit.o)

  "_OBJC_CLASS_$_FIRVisionImage", referenced from:

      objc-class-ref in libRNMlKit.a(RNMlKit.o)

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

The following build commands failed:

        Ld /Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/Project.app/Project normal x86_64
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/Project.app
An error was encountered processing the command (domain=IXUserPresentableErrorDomain, code=1):
This app could not be installed at this time.
Failed to chmod /Users/r634092/Library/Developer/CoreSimulator/Devices/E5B14B56-335E-417F-8209-4525694E4C25/data/Bundle/Application/781B1B77-DEE5-48B9-8A15-5F4E434E5444/Project.app/Project : No such file or directory
Failed to chmod /Users/r634092/Library/Developer/CoreSimulator/Devices/E5B14B56-335E-417F-8209-4525694E4C25/data/Bundle/Application/781B1B77-DEE5-48B9-8A15-5F4E434E5444/Project.app/Project : No such file or directory
Underlying error (domain=MIInstallerErrorDomain, code=4):
        Failed to chmod /Users/r634092/Library/Developer/CoreSimulator/Devices/E5B14B56-335E-417F-8209-4525694E4C25/data/Bundle/Application/781B1B77-DEE5-48B9-8A15-5F4E434E5444/Project.app/Project : No such file or directory
Launching com.Project
com.Project: -1
An error was encountered processing the command (domain=FBSOpenApplicationServiceErrorDomain, code=1):
The request to open "com.Project" failed.
The request was denied by service delegate (SBMainWorkspace) for reason: NotFound ("Application "com.Project" is unknown to FrontBoard").
Underlying error (domain=FBSOpenApplicationErrorDomain, code=4):
        The operation couldn’t be completed. Application "com.Project" is unknown to FrontBoard.
Application "com.Project" is unknown to FrontBoard.
ErickMaeda commented 5 years ago

@lake-effect Any update of this issue?

lake-effect commented 5 years ago

I did eventually resolve all this. Let me see if I can summarize my changes and get back to this issue.

lake-effect commented 5 years ago

Okay, so, I performed the manual iOS configuration steps in the README, followed by these steps:

  1. Ensure you have the associated Firebase libraries somewhere like src/ios/Firebase/ so they are reachable at build time
  2. Add the associated headers from each required .framework file to the XCode project file in XCode
  3. Optionally replace the RNCamera project file with projectWithoutFaceDetection.pbxproj as given in their docs
  4. Modify the RNMLKit XCode project to include the relevant headers from your Firebase folder it needs
  5. Copy the new RNMlkit.xcodeproj and RNMlKit.xcworkspace files with those resources imported into them someplace in your source control along with a script to copy them over the old ones at npm postinstall
  6. Add execution of that script to npm postinstall. I have something like:
`"postinstall": "node ./scripts/android/android-release-gradle-fix.js; cd node_modules/react-native; exec ./scripts/ios-install-third-party.sh; cd third-party/glog-0.3.5; exec ../../scripts/ios-configure-glog.sh; cd ../../../..; exec mlkitconfig/init.sh; react-native link"`

You may recognize some of the calls there, and at this point you should be able to build.

The only open question at that point is adding the header paths to the RNMlkit project each time it's updated, which is a chore.

1natsu172 commented 5 years ago

Hi, the same problem occurs with cocoapods in my environment. #import <FirebaseMLVision/FirebaseMLVision.h>

I think this is not a problem only for manual installation… 🤦‍♂️

eyes2design commented 5 years ago

import <FirebaseMLVision/FirebaseMLVision.h>

/react-native-firebase-mlkit/ios/RNMlKit.m:7:9: 'FirebaseMLVision/FirebaseMLVision.h' file not found I have in my Podfile this: pod 'Firebase/Core' pod 'Firebase/MLVision' pod 'Firebase/MLVisionLabelModel' pod 'Firebase/MLVisionTextModel'

I have checked that the framework exists in the build and that libRNMLKit.a is added to the link binary with libs and the RNMLKit xcodeproj is in the libs folder for the app.

I don't know what else to check it can't find the header file...

fjsandov commented 5 years ago

Same error #import <FirebaseMLVision/FirebaseMLVision.h> when I try to build it. I used react-native link so it isn't only a manual installation issue as @1natsu172 said. Does anyone know how to fix it?

tienlx91 commented 5 years ago

@fjsandov add $(PROJECT_DIR)/../../../ios/Pods/FirebaseMLVision/Frameworks to System Framework Search Path on RNMLkit Project will solve the problem.

I have to re-add if every time I clean the project and remove node_modules folder

image

fjsandov commented 5 years ago

@tienlx91 thank you! it is building the project now, I hope it can be resolved without this manual fix every time you clean the project. Again, thank you @tienlx91. 😄

oagostinho commented 5 years ago

@tienlx91 I have the same problem but with your information, I could resolve the issue.

what can we do to resolve this situation automatically? Maybe could try to resolve this issue. What do you think?

ps1312 commented 5 years ago

@mateusc42 any update??

davevilela commented 4 years ago

@mateusc42 any update??