Skip to content

Support Add2App for iOS even if the main Podfile already has post_install#32791

Closed
truongsinh wants to merge 4 commits intoflutter:masterfrom
truongsinh:patch-1
Closed

Support Add2App for iOS even if the main Podfile already has post_install#32791
truongsinh wants to merge 4 commits intoflutter:masterfrom
truongsinh:patch-1

Conversation

@truongsinh
Copy link
Contributor

@truongsinh truongsinh commented May 16, 2019

Description

Right now, https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps breaks if iOS project already has post_install snippet, see #26212

Related Issues

Tests

There is no test at the moment.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.

In https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps, the instruction should be changed to:

  flutter_application_path = 'path/to/my_flutter/'
  eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
# ...
    post_install do |installer|
      flutter_post_install(installer)
    end
  • No, this is not a breaking change.

…install`

flutter#24342 (comment)
https://stackoverflow.com/questions/40508957/invalid-podfile-file-specifying-multiple-post-install-hooks-is-unsupported
CocoaPods/CocoaPods#6172

In https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps, the instruction should be changed to:

```
  flutter_application_path = 'path/to/my_flutter/'
  eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
# ...
    post_install do |installer|
      flutter_post_install(installer)
    end
```
@Piinks Piinks added the tool Affects the "flutter" command-line tool. See also t: labels. label May 16, 2019
@LinusU
Copy link

LinusU commented Jun 11, 2019

Yes, this is great! 🚀

Since I have a deployment target of iOS 12 in my main app, my app doesn't build arm 32-bit code, but since some of the pods have a much lower deployment target they do. This leaves me with linking errors when I'm trying to archive the app, and the only fix I've found is to bump the deployment target to 12 on all my pods as well.

This leaves me in a state where I have to manually update the podhelper.rb every time I'm doing a release (since it's an autogenerated file I lose the changes all the time), to let the post-install hook add the updated deployment target...

ref: CocoaPods/CocoaPods#4859 (comment)

@blasten
Copy link

blasten commented Jul 18, 2019

cc @jmagman

@jmagman jmagman self-requested a review July 18, 2019 19:45
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break CocoaPods in the module? Now they don't have a post_install step.
What if we keep this flutter_post_install method, and add this to the end of the file:

post_install do |installer|
  flutter_post_install(installer)
 end

And then we can update the documentation to either require the module podhelper and call that method in an existing post_install, or do what mostly works now for host apps without CoocaPods and eval?

So the host app becomes:

require 'flutterapp/.ios/Flutter/podhelper.rb
post_install do |installer|
... existing post_install...
  flutter_post_install(installer)
end

Or stays:

eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

@jmagman jmagman added a: existing-apps Integration with existing apps via the add-to-app flow platform-ios iOS applications specifically labels Jul 18, 2019
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good change.

  1. The Podfile template needs to call the correct new method, otherwise the module will never install the pods.
    https://github.com/flutter/flutter/blob/master/packages/flutter_tools/templates/module/ios/host_app_ephemeral_cocoapods/Podfile.copy.tmpl
  2. I believe the framework_dir is the same directory as the podhelper __dir__, so I don't think it needs to be global or even passed in.
engine_dir = File.join(__dir__, 'engine')

@@ -3,6 +3,9 @@ platform :ios, '8.0'
target 'Runner' do
flutter_application_path = '../'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like it does anything with the new global $flutter_application_path.

@jmagman
Copy link
Member

jmagman commented Jul 24, 2019

You had a good solution to adding a method to the podhelper so existing Podfiles don't get clobbered. I took a stab at a larger change that should hopefully solve things in a more complete, more CocoaPods-friendly way, and included the spirit of your change:
#36793
When that lands, you should be able to just update your Podfile targets that need the Flutter symbols, plugins, etc:

load File.join('my_flutter', '.ios', 'Flutter', 'podhelper.rb')
target 'MyApp' do
  install_all_flutter_pods 'my_flutter'
end

There will no longer be any post_install hooks required by Flutter.

@jmagman
Copy link
Member

jmagman commented Jul 31, 2019

@truongsinh I'm hoping your issue is fixed by #36793. You can migrate your Podfile as I suggested above, and try it on the master channel. https://github.com/flutter/flutter/wiki/Flutter-build-release-channels
If it's not resolved, please file an issue and @ me!

@jmagman jmagman closed this Jul 31, 2019
@truongsinh truongsinh deleted the patch-1 branch July 31, 2019 03:03
@truongsinh
Copy link
Contributor Author

Screen Shot 2019-07-31 at 1059 08

A quick try seems that the current master of Flutter assumes FLUTTER_ROOT is set, but it is not necessarily true, nor mentioned in https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps#ios

@jmagman
Copy link
Member

jmagman commented Jul 31, 2019

Screen Shot 2019-07-31 at 1059 08

A quick try seems that the current master of Flutter assumes FLUTTER_ROOT is set, but it is not necessarily true, nor mentioned in https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps#ios

You need to remove the xcode_backend build script phase you previously added to the app. You no longer need it. I was going to write up migration instructions tomorrow but you were too fast!

@truongsinh
Copy link
Contributor Author

after removing xcode_backend build scrip and some other small changes, it works 🎉

@jmagman
Copy link
Member

jmagman commented Jul 31, 2019

@truongsinh What were the "other small changes"? I want to make sure I cover everything in the migration instructions.

@truongsinh
Copy link
Contributor Author

truongsinh commented Aug 1, 2019

@truongsinh What were the "other small changes"? I want to make sure I cover everything in the migration instructions.

It might be specific to our app only, but anyway 2 things

1

unrecognized selector applicationDidBecomeActive

our app delegate extends/implements FlutterAppDelegate, FlutterStreamHandler

class AppDelegate: FlutterAppDelegate, FlutterStreamHandler {

down there in this class, we used to override applicationDidBecomeActive and call super.applicationDidBecomeActive, but in this version, calling super will crash the app

    override func applicationDidBecomeActive(_ application: UIApplication) {
        // .. do own own stuff

        // can no longer call supper (used to be able to call in previous Add2App version) because
        // `reason: '-[myApp.AppDelegate applicationDidBecomeActive:]: unrecognized selector sent to instance 0x6000011faf00'`
        // super.applicationDidBecomeActive(application)
        
    }

2

flutterEngine is no longer a binaryMessenger protocol, but need to change to flutterEngine.binaryMessenger

-        eventChannel = FlutterEventChannel.init(name: eventChannelName, binaryMessenger: flutterEngine)
-        methodChannel = FlutterMethodChannel.init(name: methodChannelName, binaryMessenger: flutterEngine)
+        eventChannel = FlutterEventChannel.init(name: eventChannelName, binaryMessenger: flutterEngine.binaryMessenger)
+        methodChannel = FlutterMethodChannel.init(name: methodChannelName, binaryMessenger: flutterEngine.binaryMessenger)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: existing-apps Integration with existing apps via the add-to-app flow platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants