Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter plugin `geolocator-Swift.h` file not found

I have created a small Flutter plugin which can be used to monitor location changes in you Flutter application (source: https://github.com/baseflowit/flutter-geolocator). After extensive testing using the example project that is part of the project structure (as generated by the Flutter CLI) we decided to publish the plugin to make it available to the world.

Now we received some feedback that when you include the package from the online Dart Packages repo into your Flutter App, the iOS version doesn't compile and returns the following exception:

/Users/maurits/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-0.0.2/ios/Classes/GeolocatorPlugin.m:2:9:
fatal error: 'geolocator/geolocator-Swift.h' file not found

This error occurs when running the Flutter App in debug mode, but also when making a iOS package using flutter build ios --release.

I am a bit lost where this error comes from since the example app that is part of the Geolocator project works without any problems. I know the geolocator/geolocator-Swift.h file is autogenerated, so to me it looks like that the file doesn't end up in the final Dart Package. To run the final Dart Package I ran the following command:

flutter packages pub publish

Here is the output of flutter doctor -v:

[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-NL)
    • Flutter version 0.5.1 at /Users/maurits/Developer/flutter
    • Framework revision c7ea3ca377 (4 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
    • Android SDK at /Users/maurits/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.0
    • ANDROID_HOME = /Users/maurits/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 25.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] VS Code (version 1.24.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected devices (1 available)
    • iPhone X • 69C349CF-81E1-47E8-B35A-A149D885CE43 • ios • iOS 11.4 (simulator)

Any help would be greatly appreciated.

like image 523
Maurits van Beusekom Avatar asked Jun 27 '18 07:06

Maurits van Beusekom


2 Answers

you go to Ios/Podfile add the following line:

use_frameworks! # required by Geolocator

Like the following

Prepare symlinks folder. We use symlinks to avoid having Podfile.lock referring to absolute paths on developers' machines.

use_frameworks! # required by Geolocator
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')

After this add

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

Like the following:

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.2' # added this
    end
  end
end
like image 163
Bé Tập Code Avatar answered Nov 11 '22 00:11

Bé Tập Code


Since the plugin is written using Swift, the consuming Flutter app should be based on the Swift project template:

$ flutter create -i swift my_app

Adding geolocator: to the pubspec.yaml and building my_app for iOS then works for me using the latest Flutter beta.

[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-US)
like image 43
Mikkel Ravn Avatar answered Nov 11 '22 01:11

Mikkel Ravn