Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using cocoapods without react native link #239

Closed
ghost opened this issue Feb 12, 2018 · 9 comments
Closed

Allow using cocoapods without react native link #239

ghost opened this issue Feb 12, 2018 · 9 comments

Comments

@ghost
Copy link

ghost commented Feb 12, 2018

Hi AppCenter community,

I've been trying to move away from HA/CodePush and finally migrate to appcenter but I've been facing some challenges since my IOS project has been set up to integrate with cocoapods for all RN libraries I consume (including RN).

Basically, my problem is that "react-native link" links the appcenter* projects into the project "Libraries folder" however, this way the compiler has a hard time finding the React Native modules since they are set via cocoapods. I tried to setup all the appcenter* packages via cocoapods but, trying leveraging the current podspecs, was not working since they have an issue with the "s.source_files" field value.

With that said, I found a good integration approach where I can leverage completely the cocoapods.

My pod file looks like this:
...
pod 'appcenter', path: '../node_modules/appcenter/ios'
pod 'appcenter-analytics', path: '../node_modules/appcenter-analytics/ios'
pod 'appcenter-crashes', path: '../node_modules/appcenter-crashes/ios'
pod 'appcenter-push', path: '../node_modules/appcenter-push/ios'
...

However for this to work I had to change the podspecs and references in the code as shown here: https://github.com/hccoelho/AppCenter-SDK-React-Native/commit/f290b767c65f95d4f14bfa9dd026aa8cbffc792d

I tested everything locally and it works great, however, I could not find a good way to point my package.json dependencies to subfolders of the repo. Something like this would not work with npm/yarn 😞 :

"appcenter": "git+https://github.com/hccoelho/AppCenter-SDK-React-Native/*tree/develop/appcenter*#f290b767c65f95d4f14bfa9dd026aa8cbffc792d",

(you get the idea for the rest of the packages)

I would like to get your thoughts on couple things:

  • Would you be able to accept my changes (rn link would need to be updated)? If not, is there any other approach I could go with to be compliant with your design patterns but still having all integration being done via cocoapods?
  • Is there any good way to consume a git repo subfolder in the packages.json? I could not find any so I wonder if you guys have a good idea...

Disclaimer: I'm not an expert in XCode either cocoapods, however, I kinda like that everything is set via cocoapods since it feels way easier to maintain.

My env:

  • ReactNative: 0.51.0
  • Xcode version: 9.2 (9C40b)

Thank you in advance.

@bmourat
Copy link
Contributor

bmourat commented Feb 12, 2018

Hi @hccoelho,
Although there is a way to link AppCenter manually, the default way is integration through Cocoapods. Please see documentation here.
Basically, the integration process for iOS looks like this: the link scripts try to locate your Podfile, if it is not present pod init is called. After the Podfile is located, all necessary lines are added automatically, and in most cases, you don't need to modify it manually. There is a chance that the link script could not find a proper place to insert integration lines, in this case, you just need to add them manually. For example, for the current version of AppCenter and React-Native module, the lines will be following:

  pod 'AppCenter/Crashes', '~> 1.3.0'
  pod 'AppCenter/Analytics', '~> 1.3.0'
  pod 'AppCenter/Pushes', '~> 1.3.0'
  pod 'AppCenterReactNativeShared', '~> 1.2.0'

And after link script has finished all of your dependencies will be in a Pods folder. Also AppDelegate.m is also modified automatically to register AppCenter modules.

Could you please describe your integration process to find out what went wrong?

Best,
Murat

@ghost
Copy link
Author

ghost commented Feb 12, 2018

Hi @bmourat, thanks for the quick response.

The behavior you described works here when doing "react-native link" however because it links projects into the "Libraries" folder, it introduces a compilation dependency to RN which, after several hours, I could not figure how to solve it. Even when I added the whole RN projects to the Libraries folder 😭

If I do "react-native link" the following structure is set into XCode:

Pod file:
## Pods for AppCenter
pod 'AppCenterReactNativeShared', '> 1.2.0'
pod 'AppCenter/Crashes', '
> 1.3.0'

XCode:
screen shot 2018-02-12 at 9 26 44 am

The appcenter native pod libraries are added to the podfile as you describe above but the reactnative code is added via project reference into the "Libraries" folder. That's where my problem starts 😞 .

Here's the error I see when I try to run the project:

screen shot 2018-02-12 at 9 27 24 am

What I'm proposing is change the behavior of the "react-native link" to add all the references through cocoapods. Something like:

Pod file:
## Pods for AppCenter
pod 'appcenter', path: '../node_modules/appcenter/ios'
pod 'appcenter-crashes', path: '../node_modules/appcenter-crashes/ios'

screen shot 2018-02-12 at 9 37 01 am

Note that adding only the RN cocoapods will bring the native cocoapods necessary since they are set as dependencies in the spec.

With this approach, I had no compilation issue, and to me feels a bit better since it avoids my project from managing the external code.

Hope this clarifies.

Thanks for helping.
Henrique

@bmourat
Copy link
Contributor

bmourat commented Feb 12, 2018

Thanks @hccoelho
So now I understand what you mean. Basically, after react-native init you manually moved all you RN subprojects from libraries folder to be included as pods, right? Could you please attach your Podfile?

@ghost
Copy link
Author

ghost commented Feb 13, 2018

Hmm before I haven't used "react-native link" much, always used pod dependencies since it feels really easy to maintain.

As for my podfile here's what it looks like:

platform :ios, '9.0'

react_path = '../node_modules/react-native'
yoga_path = react_path + '/ReactCommon/yoga'

target 'redbeetapp' do
    pod 'Firebase/Core'
    pod 'Firebase/Performance'
    pod 'Firebase/RemoteConfig'
    pod 'HockeyAppReactNative', :path => '../node_modules/react-native-hockeyapp'
    pod "HockeySDK", :subspecs => ['AllFeaturesLib']
    pod 'SentryReactNative', :path => '../node_modules/react-native-sentry'
    pod 'CodePush', :path => '../node_modules/react-native-code-push'
    pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
    pod 'RNI18n', :path => '../node_modules/react-native-i18n'
    pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
    pod 'React', :path => react_path, :subspecs => [
    'Core',
    'ART',
    'CxxBridge',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTCameraRoll',
    'RCTGeolocation',
    'RCTImage',
    'RCTNetwork',
    'RCTPushNotification',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'RCTLinkingIOS',
    'DevSupport'
    ]
    pod 'yoga', :path => yoga_path
    pod 'RNFirebase', :path => '../node_modules/react-native-firebase'

    # Third party deps
    pod 'DoubleConversion', :podspec => react_path + '/third-party-podspecs/DoubleConversion.podspec'
    pod 'GLog', :podspec => react_path + '/third-party-podspecs/GLog.podspec'
    pod 'Folly', :podspec => react_path + '/third-party-podspecs/Folly.podspec'

   ## Pods for AppCenter
   pod 'appcenter', path: '../node_modules/appcenter/ios'
   pod 'appcenter-crashes', path: '../node_modules/appcenter-crashes/ios'

    # PLEASE DO NOT ADD TO THIS LIST. ONLY REMOVE FROM IT.
    skip_treat_warnings_as_errors = [
    'React',
    'CodePush',
    'SentryReactNative',
    'KSCrash',
    'GTMSessionFetcher',
    'GLog',
    'Folly'
    ]

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                if !skip_treat_warnings_as_errors.include?(target.name)
                    config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
                end
                if skip_treat_warnings_as_errors.include?(target.name)
                    config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = 'YES'
                end
            end
        end
    end
end

Thoughts?

@ghost
Copy link
Author

ghost commented Feb 18, 2018

@bmourat did you have the chance to see my last post?

@bmourat
Copy link
Contributor

bmourat commented Feb 19, 2018

Hey @hccoelho

Sorry for the late response, but we are still discussing this feature.

Best,
Murat

@guperrot guperrot changed the title Consume AppCenter exclusively via XCode CocoaPods Allow using cocoapods without react native link Feb 23, 2018
@guperrot guperrot removed the support label Feb 26, 2018
@guperrot
Copy link
Member

guperrot commented Apr 6, 2018

@hccoelho so #244 merged based on the fact that it does not break anything for react-native link users. We might still have questions in the future for people not using it. How would you document the steps for this setup?

@guperrot
Copy link
Member

#244 was released on version 1.5.0.

@Damoness
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants