react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

[iOS] Third-party libraries not found for "staging" config: Solution!

Open danieldunderfelt opened this issue 10 years ago • 39 comments

Hi!

I installed CodePush in my app today and followed the instructions for multi-environments, where the docs say to create a "staging" project configuration. After doing that, the project would not build at all when the scheme was set to "staging", complaining that no libraries could be found. Re-linking with rnpm didn't help, but I figured out that the issue was that no third-party libraries (including code-push!) include the staging configuration, making the build fail.

The solution was this stackoverflow answer: http://stackoverflow.com/questions/30884778/how-to-compile-a-project-with-app-and-library-in-the-same-workspace-with-differe/30884779#30884779

I had to change it a bit, using the same string for "header search paths" as "framework search paths" (functionally omitting the /include part of that string), but now everything works.

I think this should be mentioned in the documentation right where the user is instructed to create the "staging" configuration.

danieldunderfelt avatar Jul 12 '16 10:07 danieldunderfelt

In my case after following the instructions on the official documentation I had to change this as well to be $PODS_BUILD_DIR/Release$(EFFECTIVE_PLATFORM_NAME) screen shot 2017-09-16 at 17 38 37

mtt87 avatar Sep 16 '17 16:09 mtt87

These fixes don't seem to work on CI servers, since the Release build path won't have any build or header files in it.

Any thoughts on fixes or running on a CI (Buddy Build or MSFT App Center?)

wprater avatar Nov 19 '17 02:11 wprater

@wprater I'm having the same issue, it works fine if I build Release first. Did you happen to get it working?

antsmo avatar Feb 06 '18 15:02 antsmo

@wprater did you get it working on your CI system ? aka buddybuild or App Center? Did you try the solution proposed by @huitsing ?

aka: https://zeemee.engineering/how-to-set-up-multiple-schemes-configurations-in-xcode-for-your-react-native-ios-app-7da4b5237966

aligfl avatar May 10 '18 21:05 aligfl

Not sure if this helps, but I had to do something similar to @fannt. Cocopods was overwriting the configurations:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name.downcase == 'YourTargetName
      target.build_configurations.each do |config|
        if config.name.downcase == 'staging'
          config.build_settings['CONFIGURATION_BUILD_DIR'] = '$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
        end
      end
    end
  end
end

jpaolini avatar May 11 '18 05:05 jpaolini

Someone posted a solution on another thread. Which has worked for me locally + CI (buddybuild)

Solution: https://github.com/facebook/react-native/issues/11813#issuecomment-310029148

aligfl avatar May 11 '18 10:05 aligfl

Any one having an issue when using tipsi-stripe and having multiple deployments? My pod file

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

workspace 'appname'

target 'targetNameTests' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for targetName
  pod 'AppCenter/Crashes', '~> 1.6.1'
  pod 'AppCenter/Analytics', '~> 1.6.1'
  pod 'AppCenterReactNativeShared', '~> 1.5.1'
  # Stripe
  pod 'Stripe', '~> 11.2.0'

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

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

I've set Per-configuration Build Products Path for Staging to $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) Also I've updated PODS_CONFIGURATION_BUILD_DIR for Staging to ${PODS_BUILD_DIR}/Release$(EFFECTIVE_PLATFORM_NAME)

Im getting the following:

ld: library not found for -lStripe
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Amurmurmur avatar Jun 23 '18 15:06 Amurmurmur

Hi @Amurmurmur, I'm sure that problem is still in CONFIGURATION_BUILD_DIR and CONFIGURATION_TEMP_DIR settings. I've just created new ReactNative application, copied your Podfile, actualized it to this:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

workspace 'appname'

target 'Issue426' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # React Native requirements
pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge', # Include this for RN >= 0.47
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # Needed for debugging
    'RCTAnimation', # Needed for FlatList and animations running on native UI thread
    # Add any other subspecs you want to use in your project
 ]
 # Explicitly include Yoga if you are using RN >= 0.42.0
 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'

  # Pods for targetName
  pod 'AppCenter/Crashes', '~> 1.6.1'
  pod 'AppCenter/Analytics', '~> 1.6.1'
  pod 'AppCenterReactNativeShared', '~> 1.5.1'
  # Stripe
  pod 'Stripe', '~> 11.2.0'

end

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

then executed pod install, opened generated appname.xcworkspace in XCode, added new Staging configuration (based on Release configuration), added new Staging scheme, updated Pre-configuration Build Files Path and Pre-configuration Intermediate Build Files Path for both Issue426 and Pods project. After this steps my demo project built successfully.

Please try my steps and if the issue won't be solved provide me with sample project that I could able to reproduce your situation and help to fix it.

NickToropov avatar Jun 25 '18 09:06 NickToropov

for me worked with


post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
              if config.name == 'Staging'
                  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.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

jerson avatar Jul 07 '18 02:07 jerson

for me i just need set like this

post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
        if config.name == 'Staging'
            config.build_settings['CONFIGURATION_BUILD_DIR'] = '$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
        end
    end
end

pppluto avatar Nov 10 '18 11:11 pppluto

If anybody is still struggling with this issue - there is a simple way to differentiate between Codepush staging and release keys using the same "Release" configuration if you already do your builds with Fastlane.

You basically need to have these lines in your Info.plist:

<key>CodePushDeploymentKey</key>  
<string>$(CODEPUSH_KEY)</string>

and then, assuming you already have different Fastlane lanes for staging and release, add appropriate Codepush key for each lane in form of a gym param:

xcargs: "CODEPUSH_KEY=<your staging/release key>"

The key will be inserted during build process and that's about it! This approach definitely does not cover all cases, but could be useful for those who are searching for a simplified solution without the need to edit your xcode project file.

AlgirdasVZ avatar Apr 05 '19 10:04 AlgirdasVZ

I got it solved and implemented for several projects. Here is what I did:

  1. add that snippet to the end of Podfile:
post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
              if config.name == 'Staging'
                  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.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
  1. Update build paths:

Set Staging value for Per-configuration Build Products Path and Per-configuration intermediate Build Files path to $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) so it looks the same as Release one

  1. Reinstall pods.

From project root: cd ios && pod deintegrate && pod install

  1. done. Try to archive with that target to test

NOTE: In AppCenter I was having build failures when it's archiving successfully locally for staging target. I got it solved by removing build config from that branch and adding it back, seems like it has some kind of caching issues idk

nikopolidi avatar Aug 30 '19 17:08 nikopolidi

can anyone tell me where I can find my BUILD_DIR and EFFECTIVE_PLATFORM_NAME? @nikopolidi @mrPluto @jerson @sergey-akhalkov @Almouro @Amurmurmur,

JimmyDLA avatar Dec 10 '19 04:12 JimmyDLA

@JimmyDLA You can find it in Xcode https://stackoverflow.com/a/11657874

Amurmurmur avatar Dec 11 '19 11:12 Amurmurmur

none of these answers solve my problem.

chj-damon avatar Jun 10 '20 10:06 chj-damon

Just an FYI what worked in my case:

After creating the new configuration Staging, simply run pod deintegrate && pod install inside the ios folder of your Project. CocoaPods will then create all configurations on its own.

Staging Build -> Success Staging Archive -> Success

Release Build -> Success Release Archive -> Success

TwR-Slice avatar Aug 19 '20 10:08 TwR-Slice

For what it's worth, there are a few easier ways to handle this issue, after attempting without success to add a configuration, I decided it was overkill for a single value change.

Method 1: Use info.plist variable substitution, xcargs a and a default value (post xcode 11.4)

  • Set the deployment key to $(CODEPUSH_KEY:default=209348572039487520934875) in info.plist
  • We use fastlane, so calling gym/build_app with xcargs injected in from env looks like this:

build_app(scheme: "Release", export_method: "app-store", xcargs: "CODEPUSH_KEY='#{ENV["CODEPUSH_KEY"]}'"

Method 2: Use a Run Script

  • Target -> Build Phases -> Click plus -> New Run Script Phase.
  • add something like this: plutil -replace CodePushDeploymentKey -string $CODEPUSH_KEY ./APPNAME/Info.plist

Method 3: Set in JavaScript

  • did you know there is a setDeploymentKey method in the plugin for both iOS and Android? No? Cool, wasn't just me.
  • Turns out you can just pass in some configuration when starting your app, like this. This way the keys can live in your code, or however you are dealing with env vars on the javascript side. We use react-native-config, and have a staging and production env file.
const Application = __DEV__
  ? App
  : codePush({
      deploymentKey:
        Platform.OS === 'ios'
          ? config.IOS_CODE_PUSH_DEPLOYMENT_KEY
          : config.ANDROID_CODE_PUSH_DEPLOYMENT_KEY,
    })(App);

export default Application;

Voila, it works. And you can go back to hating Apple, Xcode and everything associated with them in peace.

tabrindle avatar Apr 16 '21 14:04 tabrindle

i had the same problem but went away after i ran pod install --repo-update

MRezaBaiat avatar Feb 01 '22 12:02 MRezaBaiat

Just an FYI what worked in my case:

After creating the new configuration Staging, simply run pod deintegrate && pod install inside the ios folder of your Project. CocoaPods will then create all configurations on its own.

Staging Build -> Success Staging Archive -> Success

Release Build -> Success Release Archive -> Success

After following the Multi-Deployment Testing guide we encounter similar errors. They were fixed by pod deintegrate && pod install. Thank you.

Gamote avatar May 31 '23 15:05 Gamote