Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Build errors for iOS in ObjC based apps #7

Open
LugonjaAleksandar opened this issue Aug 28, 2019 · 16 comments
Open

Build errors for iOS in ObjC based apps #7

LugonjaAleksandar opened this issue Aug 28, 2019 · 16 comments
Labels
flutter issue Issue caused or blocked by upstream flutter issue

Comments

@LugonjaAleksandar
Copy link

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
Copy link
Contributor

Does the example in this repo build for you?

@MisterJimson
Copy link
Contributor

Also, is your iOS app Swift or ObjC?

@LugonjaAleksandar
Copy link
Author

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
Copy link
Contributor

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

@MisterJimson
Copy link
Contributor

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

@LugonjaAleksandar
Copy link
Author

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
Copy link
Contributor

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.

@MisterJimson MisterJimson changed the title Build errors on iOS simulator Build errors for iOS in ObjC based apps Aug 29, 2019
@MisterJimson MisterJimson added the bug Something isn't working label Aug 29, 2019
@ericwindmill
Copy link

ericwindmill commented Aug 29, 2019

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
Copy link
Contributor

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

@ericwindmill
Copy link

@MisterJimson yes, I can run the example app

@LugonjaAleksandar
Copy link
Author

@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
Copy link

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

@MisterJimson
Copy link
Contributor

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.

  • Add use_frameworks! to the end of the Runner section in /ios/Podfile
  • Set Swift version in your iOS Runner project.
    • Open the project with Xcode.
    • In Runner, File -> New -> File -> Swift File. Name it anything.
    • Xcode will ask you if you wish to create Bridging Header, click yes.
    • Go to Runner Build Settings and set SWIFT_VERSION to either 4.2 or 5.0
    • Delete the Swift file created in step 2
    • Delete the Bridging Header created in step 3
  • flutter clean
  • In /ios pod install --repo-update

@ericwindmill
Copy link

ericwindmill commented Aug 30, 2019

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
Copy link
Contributor

@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
Copy link
Author

@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...

@MisterJimson MisterJimson added flutter issue Issue caused or blocked by upstream flutter issue and removed bug Something isn't working labels Sep 9, 2019
@MisterJimson MisterJimson pinned this issue Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flutter issue Issue caused or blocked by upstream flutter issue
Projects
None yet
Development

No branches or pull requests

3 participants