Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

iOS build failed after adding "use_frameworks!" #36

Closed
ailic88 opened this issue Jun 28, 2019 · 9 comments
Closed

iOS build failed after adding "use_frameworks!" #36

ailic88 opened this issue Jun 28, 2019 · 9 comments
Assignees
Labels
bug Something isn't working fixed

Comments

@ailic88
Copy link

ailic88 commented Jun 28, 2019

My podfile:

platform :ios, '9.3'

target 'Runner' do
use_frameworks!
flutter_application_path = '../'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
end
pre_install do |installer|
# workaround for CocoaPods/CocoaPods#3289
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end

When I add "use_frameworks!" in podfile I get follow error.

While building module 'flutter_ffmpeg' imported from /Users/aleksandar/Projects/flutter-comment-wall/.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.m:7:
    In file included from <module-includes>:1:
    In file included from /Users/aleksandar/Projects/flutter-comment-wall/.ios/Pods/Target Support Files/flutter_ffmpeg/flutter_ffmpeg-umbrella.h:13:
    /Users/aleksandar/.pub-cache/git/flutter-ffmpeg-e6631d4ed08b817f44d41ff03469f6ce482feb14/packages/flutter_ffmpeg_min-gpl_lts/ios/Classes/FlutterFFmpegPlugin.h:21:9: error: include of non-modular header
    inside framework module 'flutter_ffmpeg.FlutterFFmpegPlugin': '/Users/aleksandar/Projects/flutter-comment-wall/.ios/Pods/mobile-ffmpeg-min-gpl/mobileffmpeg.framework/Headers/MobileFFmpegConfig.h'
    [-Werror,-Wnon-modular-include-in-framework-module]
    #import <mobileffmpeg/MobileFFmpegConfig.h>
            ^

Pubspec.yaml

git:
  url: git://github.com/tanersener/flutter-ffmpeg.git
  ref: v0.2.3
  path: packages/flutter_ffmpeg_min-gpl_lts

Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F203)

After I tried https://stackoverflow.com/questions/27776497/include-of-non-modular-header-inside-framework-module I got this:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MobileFFmpegConfig", referenced from:
      objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
  "_OBJC_CLASS_$_MobileFFmpeg", referenced from:
      objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
  "_OBJC_CLASS_$_ArchDetect", referenced from:
      objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@tanersener tanersener self-assigned this Jun 28, 2019
@tanersener tanersener added the question Further information is requested label Jun 28, 2019
@tanersener
Copy link
Owner

After I tried https://stackoverflow.com/questions/27776497/include-of-non-modular-header-inside-framework-module I got this:

Which solution did you try from that stackoverflow thread? I've tested setting Allow Non-modular includes in Framework Modules flag to true and it worked for me.

@vlada3003
Copy link

When Allow Non-modular includes in Framework Modules was added the linking error happens as @ailic88 noted:
Undefined symbols for architecture arm64:
"OBJC_CLASS$_MobileFFmpegConfig", referenced from:
objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
"OBJC_CLASS$_MobileFFmpeg", referenced from:
objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
"OBJC_CLASS$_ArchDetect", referenced from:
objc-class-ref in flutter_ffmpeg(FlutterFfmpegPlugin.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@vlada3003
Copy link

vlada3003 commented Jul 1, 2019

So, I have managed to reproduce this on clean projects.
I have created an empty flutter project with flutter_ffmpeg library in pubspec.yaml and I have included it into an empty XCode workspace with Add2App.
Steps to reproduce:

  1. Create a flutter module with Add2App.
  2. Create an empty XCode project
  3. Add a flutter module to the XCode project per instructions on Add2App.
  4. Add use_frameworks! to the empty XCode project's target.
  5. Set Allow non-modular headers to yes.
  6. Build.

Flutter module pubspec.yaml:

name: test_flutter_add_to_app
description: A new flutter module project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
#
# This version is used _only_ for the Runner app, which is used if you just do
# a `flutter run` or a `flutter make-host-app-editable`. It has no impact
# on any other native host app that you embed your Flutter project into.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  flutter_linkify: ^2.1.0
  provider: ^3.0.0+1
  url_launcher: ^5.0.3
  flutter_webview_plugin: ^0.3.5
  package_info: ^0.4.0+4
  shared_preferences: ^0.5.3+1
  path_provider: ^0.5.0+1
  image_cropper: ^1.0.2
  image_picker: ^0.6.0+10
  # The Dart Linter package defines lint rules that identify and report on "lints" found in Dart code.
  # Linting is performed by the Dart analysis server and the dartanalyzer commandline tool.
  # this is not the newest version, but 72 collides with tests!
  linter: ^0.1.91
  connectivity: ^0.4.3+2
  chewie: ^0.9.7
  photo_view: ^0.3.3
  cached_network_image: ^0.8.0
  percent_indicator: ^2.1.0
  permission: ^0.1.2

  flutter_ffmpeg:
    git:
      url: git://github.com/tanersener/flutter-ffmpeg.git
      ref: v0.2.3
      path: packages/flutter_ffmpeg_min-gpl_lts

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add Flutter specific assets to your application, add an assets section, 
  # like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add Flutter specific custom fonts to your application, add a fonts
  # section here, in this "flutter" section. Each entry in this list should
  # have a "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages


  # This section identifies your Flutter project as a module meant for
  # embedding in a native host app.  These identifiers should _not_ ordinarily
  # be changed after generation - they are used to ensure that the tooling can
  # maintain consistency when adding or modifying assets and plugins.
  # They also do not have any bearing on your native host application's
  # identifiers, which may be completely independent or the same as these.
  module:
    androidPackage: com.example.test_flutter_add_to_app
    iosBundleIdentifier: com.example.testFlutterAddToApp

Flutter module Podfile:

platform :ios, '9.3'

target 'Runner' do
  flutter_application_path = '../'
  eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
end

Test iOS project Podfile:

platform :ios, '9.3'

target 'flutterTest' do
  use_frameworks!
end

#Flutter
flutter_application_path = './../test_flutter_add_to_app/'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
framework_dir = File.join(flutter_application_path, '.ios', 'Flutter')

pre_install do |installer|
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end

@tanersener
Copy link
Owner

tanersener commented Jul 2, 2019

You are manually importing a flutter module which depends on flutter_ffmpeg. It is a pretty complex integration. There are a lot of things that need to be done manually.

Can you test the following steps as workaround? You don't need to set Allow Non-modular includes in Framework Modules flag to YES for this.

In your test application:

1. Create Modules directory for mobileffmpeg.framework

mkdir Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Modules

2. Download the following modulemap file, unzip and move it inside the Modules directory

module.modulemap.zip

mv module.modulemap Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Modules

3. Delete #include "libavutil/ffversion.h" @ line 23 from MobileFFmpeg.h

vi Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Headers/MobileFFmpeg.h

4. Delete #include "libavutil/log.h" @ line 26 from MobileFFmpegConfig.h

vi Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Headers/MobileFFmpegConfig.h

5. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add all frameworks under the Pods/mobile-ffmpeg-https directory to Link Binary With Libraries section.

6. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add all system libraries/frameworks listed in Step 4 of Importing-iOS-Frameworks guide.

7. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add AVFoundation system framework.

@vlada3003
Copy link

Thanks man!!!
I've been wrecking my head around this for the past 5 days.
Do you know if it's possible for this to work Out of the box with some script when importing flutter-ffmpeg? I'm sorry if this is a rudimentary question, but I'm not an iOS dev.

@tanersener tanersener added bug Something isn't working and removed needs-analysis question Further information is requested labels Jul 2, 2019
@tanersener
Copy link
Owner

tanersener commented Jul 2, 2019

I'm glad to hear that it worked for you.

Well, steps from 1 to 4 are already in the pipeline and will be included in the next release.
Steps 5, 6 and 7 are necessary to manually import the plugin. I can't create a script to apply those steps but I can create a README section about manually importing the plugin and put these three instructions there.

@vlada3003
Copy link

Good to know! I think that README would be fine. Especially for the next person who tries to do this. I think this issue can be closed. And again, thank you for your help!

@tanersener
Copy link
Owner

You're welcome

@tanersener
Copy link
Owner

1. Create Modules directory for mobileffmpeg.framework

mkdir Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Modules

2. Download the following modulemap file, unzip and move it inside the Modules directory

module.modulemap.zip

mv module.modulemap Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Modules

3. Delete #include "libavutil/ffversion.h" @ line 23 from MobileFFmpeg.h

vi Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Headers/MobileFFmpeg.h

4. Delete #include "libavutil/log.h" @ line 26 from MobileFFmpegConfig.h

vi Pods/mobile-ffmpeg-https/mobileffmpeg.framework/Headers/MobileFFmpegConfig.h

5. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add all frameworks under the Pods/mobile-ffmpeg-https directory to Link Binary With Libraries section.

6. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add all system libraries/frameworks listed in Step 4 of Importing-iOS-Frameworks guide.

7. Go to Build Phases of Pods -> FlutterPluginRegistrant target and add AVFoundation system framework.

Steps from 1 to 4 are all fixed in v0.2.4 release. Steps 6, 7 and 8 are documented under the existing applications section in README.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants