HomeX-It / pusher-websocket-flutter

An unofficial Flutter plugin that wraps pusher-websocket-java on Android and pusher-websocket-swift on iOS
MIT License
30 stars 23 forks source link

Build errors for iOS in ObjC based apps #7

Open LugonjaAleksandar opened 5 years ago

LugonjaAleksandar commented 5 years ago

I've just included the plugin following tutorial found on Flutter community website, but just including library in pubspec.jamal file and running the project fails to build. Just to make sure I'm not dealing with some cached issues, I've also tried running "flutter clean" before starting the app on the simulator, but it still fails. Attached you can find logs that debug console outputs. Tried the same thing by opening Xcode and building the app, but issue is the same. ErrorMessagePusherPlugin.zip

MisterJimson commented 5 years ago

Does the example in this repo build for you?

MisterJimson commented 5 years ago

Also, is your iOS app Swift or ObjC?

LugonjaAleksandar commented 5 years ago

Example project works for me, but it is a swift project. When I've created my project with Flutter 1.0.0 I did not specify -swift flag in that command, so currently project is in Obj-C. Maybe that is the reason for this error. I can try to move it to Swift, if there is no way to fix it in Obj-C environment within the plugin code.

MisterJimson commented 5 years ago

It looks like there are ways to make it work: https://stackoverflow.com/questions/52536380/why-linker-link-static-libraries-with-errors-ios

MisterJimson commented 5 years ago

I'll also see if there is something this library can do to make it work automatically.

LugonjaAleksandar commented 5 years ago

Just to confirm, Flutter doesn't create project by default written in Swift and Kotlin with support for AndroidX, so you have to do it manually by running extra arguments when creating project:

flutter create -a kotlin -i swift --androidx flutterapp

After I've created Swift project and integrated this plugin, all compiled perfectly. Btw cocoapods file didn't change in 2 those 2 versions. Only change was with bridging header being added, so that was the root cause of the issue 99%.

MisterJimson commented 5 years ago

Yep for sure. But even in an ObjC project, you can and should be able to bring in Swift dependencies. So I want to see what we can do for this.

ericwindmill commented 5 years ago

I'm having this same issue. In fact, I've spent most of this week trying to wire up Pusher into our Flutter app. I've tried this plugin, as well as the one created by AppTree. I've also tried writing a plugin from scratch. I'm not an iOS expert, but I believe the issue is coming from pusher-swift (or it's dependencies) itself.

Or, I suppose the issue is Flutter's "problem", because the pusher-websocket-swift library is doing what it's intended to do. But, I'm un-able to wire up Flutter to it. I've tried converting the Flutter project into a Swift app from Obj-C, but to no avail.

Anyways, just commenting to give more information. We have to get pusher to work, so if I find any fixes, I'll make a PR.

edit: I can actually get it to build when I run flutter run, but it opens the app, immediately crashes, and I get no error messages.

MisterJimson commented 5 years ago

@ericwindmill does the example work for you? Just checking its not a different issue.

ericwindmill commented 5 years ago

@MisterJimson yes, I can run the example app

LugonjaAleksandar commented 5 years ago

@ericwindmill You can workaround the issue by running the command outside of the project file:

flutter create -a kotlin -i swift --androidx flutterapp

Than what you need to do is to remove ios folder from your project and copy ios folder from newly created one. Keep in mind if you had any change in the iOS code, project file, plist file, podfile or any other file, you will have to work that out before comiting to git. I had firebase in AppDelegate, google plist file, permissions in my own plist file and pods defining target iOS version to iOS 9.

ericwindmill commented 5 years ago

@LugonjaAleksandar Is the --androidx piece necessary? I ask because I already tried that method, but didn't include the androidx flag

MisterJimson commented 5 years ago

In #8 I added some docs to help setup an ObjC based app. I was able to do it and have an example ObjC based app in that PR as well.

This set of steps should work to fix this for your project.

ericwindmill commented 5 years ago

Thanks @MisterJimson. I'm looking into this now.

Let me ask a follow up question, because as I said, I am not an iOS expert by any means:

My project is a mono repo. The main app pulls in a few other Flutter apps... plugins that we've written that we hope to OS one day, as well as a "UI library" of widgets for our app. All of these other projects are pulled into the main app, and not vise versa. Do you think we'd need to update all of these to Swift projects? My initial thought is "no, that's not necessary", because that would suggest that all packages are Swift packages. However, I'm not sure why I could get example projects to build, but still not our app, after applying those steps you've outlined.

disclaimer: I tried that process yesterday, not today. It's possible that I biffed something. I'm pretty sure that I did those exact steps, but I'd need to try again to make sure. edit: I actually know I didn't delete the swift file or Bridging Header, so that could make the difference?

MisterJimson commented 5 years ago

@ericwindmill well, you shouldn't need to update any projects to Swift if this workaround works for you. In those steps, we just tell the project how to understand Swift so it can compile the dependencies, it stays as an ObjC based app.

Deleting the Bridging Header (and the Swift file) should not make a difference, its just to keep things clean. It took me a while to get it working myself, tried lots of combinations of things. Compare your project with my new example if possible.

However if those steps don't work for you, you should only need to convert the main app to Swift. From what I understand, using ObjC dependencies in a Swift app is easier than using Swift dependencies in an ObjC app (at least in the Flutter world).

LugonjaAleksandar commented 5 years ago

@LugonjaAleksandar Is the --androidx piece necessary? I ask because I already tried that method, but didn't include the androidx flag

Flag is not necessary at all, this is just a flag needed to update Android part of the project to AndroidX that some of the libraries might require you to do in latest versions. For example if you plan on using Firebase, you will need to move project to Android X. Sorry for the confusion...