Flutter-geolocator: Build fail, for iOS: 'geolocator/geolocator-Swift.h' file not found

Created on 26 Jun 2018  ·  12Comments  ·  Source: Baseflow/flutter-geolocator

running flutter build ios --release :

=== BUILD TARGET firebase_messaging OF PROJECT Pods WITH CONFIGURATION Release ===
/Users/**/development/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-0.0.1/ios/Classes/GeolocatorPlugin.m:2:9: fatal error: 'geolocator/geolocator-Swift.h' file not found

import

My doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v0.5.5, on Mac OS X 10.13.3 17D102, locale pt-PT)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✗] Android Studio (not installed)
[!] VS Code (version 1.14.2)
[!] Connected devices
! No devices available

bug

Most helpful comment

@mvanbeusekom just ran some tests in a clean freshly created flutter app - its a fact - when "use_frameworks!" is not present, the build fails.

Also, just uploaded a build to the appstore (beta still) but everything went smoothly.
image

AFAIK, at least for me, issue solved.

All 12 comments

@manuelgomes2 thank you very much for reaching out.

We analysed the issue and were able to reproduce it and are working on a fix (see PR #18)

@manuelgomes2 after contacting Google it seems that there is a problem at the moment with Flutter apps generated using Objective-C (which is the default) consuming Swift plugins. See also the feedback I received on my Stack Overflow question.

The workaround for now is to generate your app to use Swift on iOS (e.g. using the following Flutter CLI command flutter create -i swift my_app, notice the -i swift switch). I have to warn you however that this will generate a significant overhead on the App size.

In the meantime we will be working on translating the plugin from Swift to Objective-C so that the above workaround is not needed and also doesn't affect the App size in a negative way.

Thank you for you time, but the "flutter create -i swift my_app" is not the solution - i have created my ios app using "-i swift" from the beginning, but the problem persists...

One odd thing, when i open the GeneratedPluginRegistrant.m in XCode, your plugin appears in a different color (purple) to all the other plugins, and is the only one not starting with "FLT" in the name - sorry for my ignorance, but do you know why and if this is, somehow, related? Does it appear the same for you if you open this file in XCode?

Thank you.

(note, in the screenshot):
image

@mvanbeusekom another update, i've managed to build the app finally: the following line was commented on my podfile:
use_frameworks!
Uncommented the line and the app compiles using your plugin. Now the app crashes on start, but i'll look into that (probably some setup is needed for this app to use location services on ios)
Hope this helps.

@mvanbeusekom just ran some tests in a clean freshly created flutter app - its a fact - when "use_frameworks!" is not present, the build fails.

Also, just uploaded a build to the appstore (beta still) but everything went smoothly.
image

AFAIK, at least for me, issue solved.

@manuelgomes2 that is great news, thank you very much for the feedback.

Just to be sure, the probable reason your app was/ is crashing on start is related to the fact that the permission for the use of location based services are missing in the Info.plist file (documentation on which permissions to add is in the README.md file).

After some Googling I found the following thread which might be helpful (I will also add this to our README): https://github.com/flutter/flutter/issues/16049

Hi!

Seeing this issue, I see that in the beginning @manuelgomes2 was using firebase_messaging and geolocator, and he was having the issues.

Later on, he created a fresh app apparently without firebase_messaging, and was able to build it.

Manuel, were you able to mix both of them together in the same project?

That's currently my issue. Apparently, when using the Firebase plugins, one cannot combine them with another plugin that uses Swift code, as FB requires use_frameworks! to be out, and Swift code plugins require use_frameworks! to be in! :-/

(I actually expect that to be false)

@ffeu on the linked SO question you mention you run into the following error:

The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.

To me this looks like you need to specify the Swift version in your Podfile by adding the following line:

config.build_settings['SWIFT_VERSION'] = '4.1'

It should be part of the post_install block, like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '4.1'
    end
  end
end

Not sure this will work since I haven't tested it, but it is worth a try I would say. Please let me know if this helps.

P.S. I also posted the above as an answer on Stack Overflow.

Hi Maurits, it worked!! \o/

I have tested it previously, but only with '3.2'! It worked both with 4.0 and 4.1.

Thanks a lot!

I tested it using all 3.2, 4.0, 4.1 and 4.2 but still the XCode shows the error
'geolocator/geolocator-Swift.h' file not found This is the code in my file

#import "GeolocatorPlugin.h"
#import <geolocator/geolocator-Swift.h> // this line causes error

@implementation GeolocatorPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  [SwiftGeolocatorPlugin registerWithRegistrar:registrar];
}
@end

Can anyone guide me?

I think it's your Xcode version.

Check this SO question.

Was this page helpful?
0 / 5 - 0 ratings