Flutter build on iOS fails while Android build is working fine

233 Views Asked by At

First, I'm building a Flutter app for Android and iOS. While building and running on Android is working fine the iOS build is failing since I added SQLite support.

flutter run --debug
Changing current working directory to: /Users/jj/git/kellermeister/kellermeister
Launching lib/main.dart on iPhone 12 in debug mode...
Running Xcode build...
Xcode build done.                                            5,3s
Failed to build iOS app
Lexical or Preprocessor Issue (Xcode): 'sqlite3.h' file not found
/Users/jj/git/kellermeister/kellermeister/ios/Pods/SQLite.swift/Sources/SQLiteObjc/fts3_tokenizer.h:26:8


Could not build the application for the simulator.
Error launching application on iPhone 12.
/Users/jj/git/kellermeister/kellermeister/ios>

While I can see that sqlite3.h cannot be resolved I can say that a sqlite3.h could be found in:

./Pods/sqlite3/sqlite-src-3430100/sqlite3.h

My knowledge about Xcode and it's build configuration is quite limited. Also, I expected that flutter would do the magic for me here ;)

I tried already the hints which I found on the net:

rm Podfile.lock
pod install --repo-update
flutter clean
flutter run --debug

Here is my Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

Finally the output from flutter doctor -v:

flutter doctor -v
[✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-x64, locale de-DE)
    • Flutter version 3.13.6 on channel stable at /usr/local/Caskroom/flutter/3.10.6/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ead455963c (vor 4 Wochen), 2023-09-26 18:28:17 -0700
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/jj/android-sdk-macosx
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/jj/android-sdk-macosx
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2023.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 232.9559.10

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.23.0

[✓] Connected device (3 available)
    • iPhone 12 (mobile) • FDD35D44-C239-411C-BC36-2637F12451CE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 14.0 23A344 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 118.0.5993.88

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Any help is highly appreciated as I'm really stuck currently.

3

There are 3 best solutions below

1
On

I am assuming you are using the following package

https://pub.dev/packages/sqlite3

which provides dart bindings via ffi

If you are running this on Mac M1 please make sure to reinstall ffi accordingly and retry pod install

gem uninstall ffi && gem install ffi -- --enable-libffi-alloc

rm Podfile.lock flutter clean flutter pub get pod install --repo-update flutter run --debug

0
On

maybe this will help you: take a look if you have any relative Paths under  Target ==> Built Settings ==> Framework search

If yes change them to absolute paths.

0
On

The solution was to remove explicit dependencies sqlite3_flutter_libs and (dev) sqflite_common_ffi. This resolved the issue of unresolved sqlite3.h.

I also had to set ENABLE_USER_SCRIPT_SANDBOXING=NO so that the build process could write required files.