React-native-code-push: Not working with staging environment

Created on 20 Jun 2017  路  30Comments  路  Source: microsoft/react-native-code-push

Description

Hi, we have a react native application and we recently planned to add codepush to our application.

I went through the documentation and followed the exact steps mentioned there. I create a staging profile and added staging key there but I am witnessing something strange here. Its working fine on my local device with Debug as well as Release build(staging profile).

I can see following in my xcode logs when I try to run it locally with release option:-

[CodePush] Loading JS bundle from file:///var/containers/Bundle/Application/C20B7F8E-CC2F-418C-A011-A583183FB407/wlv1.app/main.jsbundle
2017-06-20 19:17:11.093 [info][tid:com.facebook.react.JavaScript] [CodePush] Checking for update.
2017-06-20 19:17:11.093323 wlv1[4744:1122933] [CodePush] Checking for update.
2017-06-20 19:17:11.384 [info][tid:com.facebook.react.JavaScript] [CodePush] Reporting binary update (1.1.0)
2017-06-20 19:17:11.384649 wlv1[4744:1122933] [CodePush] Reporting binary update (1.1.0)
2017-06-20 19:17:13.553 [info][tid:com.facebook.react.JavaScript] [CodePush] App is up to date.

Now when i create a beta build using archive and export to app store(using same staging profile), the codepush part does not work at all. In firebase I can see that an app_update event is getting fired but I am not really sure whats going on there because I cannot see result of API call anywhere. I am pretty sure my staging key is correct because same is working on device locally.

Reproduction

Following is my JS code:-

class WealthyApp extends React.Component {

  componentDidMount () {
    // Adding event to get current net status
    NetInfo.isConnected.addEventListener("change", this.handleConnectionChange);
  }

  componentWillUnmount () {
    // Removing event to get current net status
    NetInfo.isConnected.removeEventListener("change", this.handleConnectionChange);
  }

  handleConnectionChange = (isConnected) => {
    // Dispatching action to update current net status
    this.props.dispatch({"type":"RECEIVE_IS_NET_CONNECTED",isConnected});
  };



  render () {
    if (this.props.pinStatus === null) {
      return null;
    }
    return (
      <View style={styles.container}>
        <WealthyNavigator
          pinStatus={this.props.pinStatus}
        />
      </View>
    );
  }
}


WealthyApp.propTypes = {
  "dispatch": React.PropTypes.func.isRequired,
  "pinStatus": React.PropTypes.bool
};

const styles = StyleSheet.create({
  "container": {
    "flex": 1
  }
});

function login (store) {
  const {wlStore} = store;
  const {login} = wlStore;
  const {pinStatus} = login;

  return {
    pinStatus
  };
}

module.exports = codePush(connect(login)(WealthyApp));

Following is my code present in AppDelegate.m:-

#import <CodePush/CodePush.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
#ifdef DEBUG
    jsCodeLocation = [NSURL URLWithString:@"http://192.168.225.137:8081/index.ios.bundle"];
  #else
    jsCodeLocation = [CodePush bundleURL];
  #endif
}

Can someone please help me?

Additional Information

  • react-native-code-push version: 1.17.3-beta
  • react-native version: 0.40
  • iOS/Android/Windows version: ios
  • Does this reproduce on a debug build or release build? release
documentation iOS waiting-for-clarification

Most helpful comment

Hi @jinxac, please take a look at rncp893 copy.zip
I've configured this project to use pods, release and staging schemes. Also archiving works well both for release and staging, CodePush also works correctly.
Please pay attention on podfile and this customization:


  1. screenshot 2017-07-25_09-59-32

  2. screenshot 2017-07-25_10-00-57

Please let me know if it helps or if you have any questions or see any issues.

All 30 comments

Hi @jinxac, thanks for reaching us. Could you please take a look at https://github.com/Microsoft/react-native-code-push/issues/840 and verify if you have the same issue and if https://github.com/Microsoft/react-native-code-push/issues/840#issuecomment-302635288 resolves it?

@sergey-akhalkov doesnt look the like the same issue but my BuildConfiguration is still Release under Archives section of schemes. I will try making it Staging and creating a build once.

@jinxac, got it, please let me know if any updates.

Hey @sergey-akhalkov i tried changing that Release to Staging but that breaks my pods configuration and I get error ld: framework not found Pods_wlv1 and this is coming specifically in staging, release and debug seem to be working fine.

@sergey-akhalkov Can you please me tell me what do you need from my end? Logs/More Info would love to share the necessary info

@sergey-akhalkov looks like there is something wrong with the staging environment itself. So here is what I tried doing:-

  1. Interchanged the staging and release key.
  2. Build the archive using my release scheme (which contains staging key itself) and uploaded to app store as beta build.

In this case I was able to see the changes.

Can you please let me know if I am missing something

Hi @jinxac, could you please share with me the minimal version of the app where the issue is reproduces?

@sergey-akhalkov I have shared some piece of code above. Can you please tell me once what other information is required? I will share accordingly :)

@jinxac, do I get it right if your app does not receiving any updates in case it has been archived/build with Staging scheme or you are experiencing some compile issues while trying to follow this steps?

@sergey-akhalkov setup works fine the steps linked you shared above. Yes you are right that it is not receiving updates when built with staging schemes with Pods.

When I change Release to Staging under scheme Archives it starts to throw error ld: Frameworks not found(these frameworks are specific to Pods) during Linking.I tried to dig in a bit further and saw that under BuildProducts folder I have 2 folders Release-ios and Staging-ios. My entire packages and code is under Release-ios as expected but my Pod specific packages go under Staging-ios folders. Now linker tries to link pod packages from Release-ios folder which throws error.

Now, When I change Staging to Release under staging scheme Archieves it works fine and build is created but on testflight(beta) build code push changes are not reflected and under code-push deployment app-name ls -k I see no installs recorded

Hi @jinxac, sorry for the delayed response, do you still experiencing the issue?

@sergey-akhalkov thanks for the reply.. yeah still experiencing the same issue

@sergey-akhalkov any updates?

Hi @jinxac, sorry for the delayed reply. I've investigated the problem you have and faced with linking issue while archiving. But I've successfully configured my project with Production and Staging schemes - CodePush updates work as expected. Also, I'm using the latest version of react-native and react-native-code-push, so the issue with linking could probably be here.
So I'm going to downgrade RN and CodePush versions and verify if everything works - I'll let you know if any changes.

Please also take a look at my project here: rncp893 copy.zip
If you have a chance - you could also try to downgrade RN and CodePush versions and verify if it works or not.

Thanks for the patience.

@jinxac, I've found out the root cause of linker issue - we need to change podfile like that:

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

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

  # Pods for rncp893

  pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'BatchedBridge'
  ]
  pod 'CodePush', :path => '../node_modules/react-native-code-push'

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

end

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

  # Pods for rncp893-tvOS

  target 'rncp893-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Please let me know if it helps.

Hi @jinxac, please take a look at rncp893 copy.zip
I've configured this project to use pods, release and staging schemes. Also archiving works well both for release and staging, CodePush also works correctly.
Please pay attention on podfile and this customization:


  1. screenshot 2017-07-25_09-59-32

  2. screenshot 2017-07-25_10-00-57

Please let me know if it helps or if you have any questions or see any issues.

@sergey-akhalkov Thanks a lot for your response. Let me try this out once.

Hi @jinxac, do you have any updates on this? I'm closing this for now, please feel free to reopen if needed.

Thanks @sergey-akhalkov your solution of editing build locations for project and pods worked for me.

Now I wonder how to make those changes in ci 馃槩

Hi @brookemitchell, thanks for the feedback. By CI do you mean appcenter.ms?
Please let me know if you need any help or have any questions.

Yeah no luck changing the project settings on appcenter.ms if I setup a staging scheme.

Not really your problem though, thanks for your help.

@sergey-akhalkov thanks a ton for sharing.. i am finally back to integrating this to my project again :D .. I tried the exact configuration you mentioned but when i upload the binary to itunes after building with staging scheme it throws error on itunes saying that the build is invalid (Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path.) . It works fine release scheme though. Have u faced this issue?

Hi @jinxac, thanks for reaching us again!

Have u faced this issue?

I believe not, so I don't sure how exactly I can help you here, did you tried the working sample above? Does it work for you?

@sergey-akhalkov looks like the pod libraries are getting copied into Staging folder instead of release which leads to https://github.com/facebook/react-native/issues/11813#issuecomment-331368709

/Users/harkirat/Library/Developer/Xcode/DerivedData/wlv1-grovuwlrhzpjbvenlreejvbtlwol/Build/Intermediates.noindex/ArchiveIntermediates/wlv1 Staging/BuildProductsPath
tests-MBP:BuildProductsPath harkirat$ ls
Release-iphoneos    Staging-iphoneos
tests-MBP:BuildProductsPath harkirat$
tests-MBP:BuildProductsPath harkirat$ cd Staging-iphoneos/
tests-MBP:Staging-iphoneos harkirat$ ls
GTMOAuth2       Mixpanel        QBImagePickerController
GTMSessionFetcher   Pods_wlv1.framework RSKImageCropper
GoogleToolboxForMac Protobuf        nanopb
tests-MBP:Staging-iphoneos harkirat$
tests-MBP:BuildProductsPath harkirat$ cd Release-iphoneos/
tests-MBP:Release-iphoneos harkirat$ ls
49D27CAF-3566-30BB-9FF1-63E20D4D5231.bcsymbolmap    libRCTMaterialKit.a
57C7F55D-A2AE-30F3-A6EA-9F38A1651329.bcsymbolmap    libRCTNetwork.a
5maFL9                          libRCTSettings.a
B00A891C-B9FD-3621-85B1-D7ACEEB3888C.bcsymbolmap    libRCTText.a
B881CB00-A637-3C8C-90B1-36E49E358AA1.bcsymbolmap    libRCTVibration.a
GeneratedInfoPlistDotEnv.h              libRCTWebSocket.a
Hhe8NH                          libRNDeviceInfo.a
QBImagePicker.framework                 libRNFIRMessaging.a
QBImagePicker.framework.dSYM                libRNFS.a
RSKImageCropper.framework               libRNFetchBlob.a
RSKImageCropper.framework.dSYM              libRNIntercom.a
include                         libRNMixpanel.a
libBVLinearGradient.a                   libReact.a
libBugsnagReactNative.a                 libReactNativeConfig.a
libBugsnagStatic.a                  libcxxreact.a
libCodePush.a                       libdouble-conversion.a
libRCTActionSheet.a                 libimageCropPicker.a
libRCTAnimation.a                   libjschelpers.a
libRCTCamera.a                      libthird-party.a
libRCTFBSDK.a                       libyoga.a
libRCTGeolocation.a                 wlv1.app
libRCTImage.a                       wlv1.swiftmodule
libRCTLinking.a

I am pretty aware that this is not code push issue but any help would really be appreciated :) . Thanks in advance

@jinxac, we are very "backlogged" and have no ability and time to manage such kind of issues, but please feel free to create a CodePush related issue - we'll take a look at it in order of priority.

@sergey-akhalkov i tried using https://github.com/blargity/react-native-schemes-manager for first creating a staging environment and then a taking a beta build with staging configuration. Looks like its working fine now :). Let me give a try now by changing code push keys

@sergey-akhalkov with react-native-schemes-manager I was easily able to integrate this. If someone needs any help regards integrations and multiple environments on iOS would love to help.

Hi @jinxac, I'm trying to fix this bug on my app and can't seem to make it work. I'm using CocoaPods and my XCode workspace looks exactly like the demo, but whenever I build my project my files end up scattered across both Staging/Production build folders. I'm now trying to use the schemes-manager module like you said but still am having the same issues. Keen to hear how you got this to work with CocoaPods.
Thanks.

@rodperottoni i too have cocoapods in my project, but it is working fine. What error are using exactly?
Can you share your profiles and package.json once?

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!
That definitely does not cover all cases, but should be useful for those who are searching for a simplified solution without the need to edit your xcode project file.

Was this page helpful?
0 / 5 - 0 ratings