source: unbound variable error when using Cocoapods for Firebase
Asked Answered
P

5

7

I have integrated Firebase and GoogleTagManager into my iOS app target using Cocoapods. When I build my target, Xcode constantly gives me error:


Showing Recent Messages
PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks 

mkdir -p /Users/xxx.xxx/Library/Developer/Xcode/DerivedData/MyApp-enzvpdzsyhjszqbnwiclnpszlyri/Build/Products/Debug-iphonesimulator/MyApp.app/Frameworks


/Users/xxx.xxx/Projects/MyApp/Applications/MyApp/Pods/Target Support Files/Pods-MyApp/Pods-MyApp-frameworks.sh: line 43: source: unbound variable


Command /bin/sh failed with exit code 1

I've cleaned my project multiple times, deleted the derived data folder but none of these seem to work.

My Podfile looks like this:

platform :ios, '11.0'

target 'MyApp' do

  use_frameworks!

  # Pods for MyApp
    pod 'Firebase/Core', '~> 5.19'
    pod 'Firebase/ABTesting'
    pod 'Firebase/Performance'
    pod 'Firebase/RemoteConfig'
    pod 'Firebase/Analytics'
    pod 'GoogleTagManager', '~> 7.1'
 end

Cocoapods Environment

CocoaPods : 1.5.3
        Ruby : ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
    RubyGems : 2.6.8
        Host : Mac OS X 10.14 (18A391)
       Xcode : 10.1 (10B61)
         Git : git version 2.17.2 (Apple Git-113)
Ruby lib dir : /Users/xxx.xxx/.rbenv/versions/2.4.0/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 7c9a708dce25221eabc35ed39

What is it that I am missing in my project settings that is causing this error ?

I have spent several days looking for a solution on SO / Cocoapods but in vain.

Any help in this regards would be really appreciated.

Thanks

Paulownia answered 3/5, 2019 at 7:18 Comment(4)
EDIT: CocoaPods : 1.6.1Paulownia
github.com/CocoaPods/CocoaPods/issues/…Resident
@PaulBeusterien so do I need to apply the same fix as ${EXPANDED_CODE_SIGN_IDENTITY:-} to "${source:-}" ?Paulownia
The error is suppressed when I replace all occurrences of ${source} with ${source:-} in Pods-Project-frameworks.sh file but the frameworks do not get generated in the Products directory in Pods project. @PaulBeusterien any ideas? I desperately need to get this working for my project. Any pointers would be highly appreciated.Paulownia
Y
1

I had the same issue when my framework was built with M1 chip. I was able to resolve that by removing ONLY_ACTIVE_ARCH from the Podfile installer section.

So I replaced this:

post_install do |installer|

installer.pods_project.targets.each do |target|

target.build_configurations.each do |config|
  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
  config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'

 end
end

With this:

post_install do |installer|

installer.pods_project.targets.each do |target|

target.build_configurations.each do |config|
  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
 end
end

Note: I added ['ONLY_ACTIVE_ARCH'] = 'NO' from the beginning in order to run my app in simulator with the "problematic" framework when the framework was built with non M1 chip. So I still need this line depending on the chip of the build machine.

Yalta answered 11/3, 2021 at 9:48 Comment(0)
G
0

This seems to be some peculiar issue, perhaps bash related or something. For some strange reason, it does not work with ~/Library/.../MyApp-xxxxx.../Build/Products/Release-iphoneos/ directory (Let's call it BUILD_DIR)

If 'source' is undefined, which is the case here, replacing ${source} with ${source:-} does not help because then it places a blank for source, which is not what you want.

For me another problem was rsync does not find the above directory.

Here is what I did:

  1. Let the project build and give error. This ensures that the required framework directories are created in my BUILD_DIR, and frameworks are built.

  2. Created a directory Pods-frameworks in project root directory, copied all framework directories from BUILD_DIR to this directory.

  3. In PodsMyApp-frameworks.sh, last 25 lines, calls to install_framework with all pods-related frameworks in Debug and Release modes, changed ${BUILT_PRODUCTS_DIR} to a new macro that is defined to be this new Pods-frameworks directory.

  4. Built the projects again.

That solved the problem. If pods is installed again and if there is a version change, this process may have to be repeated.

Golconda answered 24/7, 2020 at 11:56 Comment(1)
you have to remember to repeat this change to PodsMyApp-frameworkds.sh because everytime pod install is called this file is regenerated from scratch.Liken
L
0

All right, I've messed around with this issue for 4 days and finally resolved with a script.

The setup

  • RN 0.61.5 upgrading from 0.59.10
  • Xcode 11.3.1
    • multi-scheme (Staging, Beta)
    • multi-configurations (Staging, Beta)
  • CocoaPods 1.9.3

related npm packages:

    "react-native": "0.61.5",
    "@react-native-firebase/app": "^8.4.6",
    "@react-native-firebase/auth": "^9.3.1",
    "@react-native-firebase/crashlytics": "^8.4.11",
    "@react-native-firebase/database": "^7.5.12",
    "@react-native-firebase/messaging": "^7.9.1",
    "react-native-code-push": "6.3.0",
    "react-native-config": "1.4.0"

Guides and Sources Used:

Podfile:

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

project 'lend24app',
  'Debug' => :debug,
  'Release' => :release,
  'Staging' => :release,
  'Beta' => :release


target 'lend24app' do
  use_frameworks!
  $RNFirebaseAsStaticFramework = true

  # Pods for lendmn
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'RNInputMask', :path => '../node_modules/react-native-text-input-mask/ios/InputMask'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary.podspec"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders.podspec"
  pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit.podspec"


  pre_install do |installer|
    installer.analysis_result.specifications.each do |s|
      s.swift_version = '4.0' unless s.swift_version
    end
    # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}

    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
        def pod.build_type;
          # Uncomment one line depending on your CocoaPods version
          Pod::BuildType.static_library # >= 1.9
        end
      end
    end
  end

  post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
      if config.name == 'Staging' || config.name == 'Beta'
        config.build_settings['CONFIGURATION_TEMP_DIR'] = '$(PROJECT_TEMP_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
        config.build_settings['CONFIGURATION_BUILD_DIR'] = '$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
      end
    end
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if config.name == 'Staging' || config.name == 'Beta'
          config.build_settings['CONFIGURATION_TEMP_DIR'] = '$(PROJECT_TEMP_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
          config.build_settings['PODS_CONFIGURATION_BUILD_DIR'] = '${PODS_BUILD_DIR}/Release$(EFFECTIVE_PLATFORM_NAME)'
        end
      end
    end
  end

  target 'lend24appTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

This setup is outcome of gradual development of a project since 2016, so the items and actual configurations are not recommended, it's better to start from scrath!

Steps that lead to this issue, all steps fail to produce beta archive:

  1. upgrade rn through upgrade command
  2. patch up files missed through the command using RN Upgrade helper
  3. create Xcode configurations using above mentioned guide from Code Push
  4. unknown ...

somewhere along the journey I ended up with PODS_CONFIGURATION_BUILD_DIR Build Setting that has ${PODS_BUILD_DIR}/Release$(EFFECTIVE_PLATFORM_NAME) for Beta configuration

at this point Running Beta build, but archiving fails with source: unbound variable

whenever I change PODS_CONFIGURATION_BUILD_DIR to ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) or if I edit out the Podfile fix for same PODS_CONFIGURATION_BUILD_DIR change the build stage fails with

'React/RCTBridgeDelegate.h' file not found.

Digging through ...frameworks.sh it is clear that Pods build is outputted to Release-iphoneos folder while the rest is in Beta-iphoneos due to the PODS_CONFIGURATION_BUILD_DIR setting or something similar, I've tried changing to default values, but then builds fail even before reaching this Build Phase [CP] Embed Pods Frameworks

in the end I just moved everything from Release-iphoneos to Beta-iphoneos prior this phase using the following script:

+ New Run Script Phase

# Type a script or drag a script file from your workspace to insert its path.
if [[ "$CONFIGURATION" == "Debug" ]]; then
    exit 0
elif [[ "$CONFIGURATION" == "Release" ]]; then
    exit 0
fi

mv $BUILD_DIR/Release$EFFECTIVE_PLATFORM_NAME/* $BUILD_DIR/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME/

Kinda tired here, just thought it might help anyone in similar situation, wish I could help more, feedback is welcome.

Liken answered 28/11, 2020 at 7:39 Comment(0)
A
0

I think is related to c++ version that the framework uses. for me changing the framework build settings from GCC_C_LANGUAGE_STANDARD = gnu17; to GCC_C_LANGUAGE_STANDARD = gnu11; resolved the issue.

Adonic answered 25/1 at 9:37 Comment(0)
T
0

Check how the source variable is created. ie:

  if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$1"
  elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  elif [ -r "$1" ]; then
    local source="$1"
  fi

the second thing to note after adding Firebase is, it integrates with framework generation, so if you're using the cocoapods block, some custom variables might be misaligned. In this case, the basename attaches to source making it a point to investigate. Not to forget BUILT_PRODUCTS_DIR too. With all this said, this is how I got my build phase to pass in xcode: the basename must match with the file generated after running pod publish in gradle. OR: the outputFile variable must match with the files generated, Bonus: publishDir variable must match with the generated files as well.

On my side I fixed it by removing custom paths and naming the basename the same as my module name. Deleted Pods folder, regenerated everything and then ran build in xcode

Trucker answered 27/6 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.