【问题标题】:flutter build ios error after add OneSignalNotificationServiceExtension to Podfile将 OneSignalNotificationServiceExtension 添加到 Podfile 后颤振构建 ios 错误
【发布时间】:2019-10-05 12:11:56
【问题描述】:

我用过onesignal_flutter https://pub.dev/packages/onesignal_flutter

在我的颤振项目中

然后按照此步骤在此链接中为 ios 设置 onsignal sdk

https://documentation.onesignal.com/docs/flutter-sdk-setup

我在 Visual Studio 代码终端中运行这两个命令

flutter cleanflutter build ios

我收到此错误

Running pod install...                                              2.7s

Running Xcode build...                                                  

Xcode build done.                                            4.8s

Failed to build iOS app

Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode 的输出: ↳

  ld: warning: linking against a dylib which is not safe for use in application
    extensions:
    /Users/jaadara/Desktop/flutter/bin/cache/artifacts/engine/ios-release/Flutter.framework/
    Flutter
    ld: warning: linking against a dylib which is not safe for use in application
    extensions:
    /Users/jaadara/Desktop/flutter/bin/cache/artifacts/engine/ios-release/Flutter.framework/
    Flutter
    /Users/jaadara/Desktop/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_webview_plugin
    -0.3.8/ios/Classes/FlutterWebviewPlugin.m:19:55: error: 'sharedApplication' is
    unavailable: not available on iOS (App Extension) - Use view controller based solutions
    where appropriate instead.
        UIViewController *viewController = [UIApplication
        sharedApplication].delegate.window.rootViewController;
                                                          ^
    In module 'UIKit' imported from /Users/jaadara/Desktop/cicr_finals/ios/Pods/Target
    Support Files/flutter_webview_plugin/flutter_webview_plugin-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iP
    honeOS11.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:110:54:
    note: property 'sharedApplication' is declared unavailable here
    @property(class, nonatomic, readonly) UIApplication *sharedApplication
    NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate
    instead.");
                                                         ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iP
    honeOS11.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:110:54:
    note: 'sharedApplication' has been explicitly marked unavailable here
    /Users/jaadara/Desktop/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_webview_plugin
    -0.3.8/ios/Classes/FlutterWebviewPlugin.m:286:24: warning: comparison of distinct
    pointer types ('NSString *' and 'NSNull * _Nonnull') [-Wcompare-distinct-pointer-types]
      if (_invalidUrlRegex != [NSNull null] && urlString != nil) {
          ~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~
    1 warning and 1 error generated.

Encountered error while building for device.

这是我的 Podfile 代码

# Uncomment this line to define a global platform for your project
 platform :ios, '9.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 parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) { |line|
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
      plugin = line.split(pattern=separator)
      if plugin.length == 2
        podname = plugin[0].strip()
        path = plugin[1].strip()
        podpath = File.expand_path("#{path}", file_abs_path)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end

target 'Runner' do
  use_frameworks!

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')

  # Flutter Pods
  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
  if generated_xcode_build_settings.empty?
    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
  end
  generated_xcode_build_settings.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join('.symlinks', 'flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
    end
  }

  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join('.symlinks', 'plugins', p[:name])
    File.symlink(p[:path], symlink)
    pod p[:name], :path => File.join(symlink, 'ios')
  }
  target 'OneSignalNotificationServiceExtension' do
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
  end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

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

请帮忙

【问题讨论】:

    标签: ios flutter xcode10.3


    【解决方案1】:

    我有一个类似的问题,我还没有 100% 理解,但我相信文档不容易理解,而且有点过时。我把所有东西都做了两次,但不会工作,同样的错误...... 鉴于花药错误,我必须添加添加这一行,而无需添加。

    use_frameworks!
    

    试试这样的:

    # Uncomment this line to define a global platform for your project
     platform :ios, '9.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 parse_KV_file(file, separator='=')
      file_abs_path = File.expand_path(file)
      if !File.exists? file_abs_path
        return [];
      end
      pods_ary = []
      skip_line_start_symbols = ["#", "/"]
      File.foreach(file_abs_path) { |line|
          next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
          plugin = line.split(pattern=separator)
          if plugin.length == 2
            podname = plugin[0].strip()
            path = plugin[1].strip()
            podpath = File.expand_path("#{path}", file_abs_path)
            pods_ary.push({:name => podname, :path => podpath});
          else
            puts "Invalid plugin specification: #{line}"
          end
      }
      return pods_ary
    end
    
    target 'Runner' do
      use_frameworks!
    
      # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
      # referring to absolute paths on developers' machines.
      system('rm -rf .symlinks')
      system('mkdir -p .symlinks/plugins')
    
      # Flutter Pods
      generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
      if generated_xcode_build_settings.empty?
        puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
      end
      generated_xcode_build_settings.map { |p|
        if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
          symlink = File.join('.symlinks', 'flutter')
          File.symlink(File.dirname(p[:path]), symlink)
          pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
        end
      }
    
      # Plugin Pods
      plugin_pods = parse_KV_file('../.flutter-plugins')
      plugin_pods.map { |p|
        symlink = File.join('.symlinks', 'plugins', p[:name])
        File.symlink(p[:path], symlink)
        pod p[:name], :path => File.join(symlink, 'ios')
      }
      target 'OneSignalNotificationServiceExtension' do
        pod 'OneSignal', '>= 2.9.3', '< 3.0'
      end
    end
    
    # Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
    install! 'cocoapods', :disable_input_output_paths => true
    
    target 'OneSignalNotificationServiceExtension' do
      use_frameworks!
      pod 'OneSignal', '>= 2.9.3', '< 3.0'
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['ENABLE_BITCODE'] = 'NO'
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 2021-03-05
      • 2021-05-31
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 2022-11-02
      相关资源
      最近更新 更多