la-haus / flutter-segment

Segment.io library for flutter
MIT License
22 stars 139 forks source link

Can't build app on iOS after upgrading to 3.9.0 #38

Closed bhayatus closed 2 years ago

bhayatus commented 2 years ago

After upgrading to 3.9.0, I keep getting an error when Xcode tries to build the app on iOS.

Uncategorized (Xcode): Command CompileSwiftSources failed with a nonzero exit
code

Lexical or Preprocessor Issue (Xcode): Include of non-modular header inside
framework module 'segment_appsflyer_ios.SEGAppsFlyerIntegration':
'/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/Hea
ders/Public/Analytics/SEGAnalytics.h'
/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/segm
ent-appsflyer-ios/segment-appsflyer-ios/Classes/SEGAppsFlyerIntegration.h:11:8

Lexical or Preprocessor Issue (Xcode): Include of non-modular header inside
framework module 'segment_appsflyer_ios.SEGAppsFlyerIntegration':
'/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/Hea
ders/Public/Analytics/SEGAnalyticsUtils.h'
/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/segm
ent-appsflyer-ios/segment-appsflyer-ios/Classes/SEGAppsFlyerIntegration.h:12:8

Lexical or Preprocessor Issue (Xcode): Include of non-modular header inside
framework module 'segment_appsflyer_ios.SEGAppsFlyerIntegrationFactory':
'/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/Hea
ders/Public/Analytics/SEGIntegrationFactory.h'
/Users/bhayatus/mednow/suite/services/suite-mobile-customer/src/ios/Pods/segm
ent-appsflyer-ios/segment-appsflyer-ios/Classes/SEGAppsFlyerIntegrationFactory.h
:10:8

Parse Issue (Xcode): Could not build module 'segment_appsflyer_ios'
/Users/bhayatus/development/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_segment-3.9.0/ios/Classes/FlutterSegmentPlugin.m:0:8
danielgomezrico commented 2 years ago

It looks like it is related to this:

@johnsouza-loftbr do you have any idea?

johnsouza-loftbr commented 2 years ago

@danielgomezrico not yet, let me do some digging and reach you guys as soon as possible.

johnsouza-loftbr commented 2 years ago

hi @bhayatus! Can you tell me if the problem occurs when you build for debug or release?

bhayatus commented 2 years ago

@johnsouza-loftbr I didn't try release mode but building in debug mode was what led to this.

johnsouza-loftbr commented 2 years ago

@bhayatus thank you! Did some digging here and couldn't reproduce the problem. While I keep doing the dig part, let me ask you: you tried flutter clean and a XCode full clean? Sometimes XCode loses itself when working with libraries that changes dependencies. So my suggestion is:

  1. run flutter clean;
  2. clear the Derived Data folder rm -rf ~/Library/Developer/Xcode/DerivedData;
  3. rebuild the project.

After doing that, can you confirm if the problem persists please?

bhayatus commented 2 years ago

Tried what was suggested, still an issue. Here's flutter doctor on my MacBook if that helps.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.2, on macOS 12.3.1 21E258 darwin-arm, locale
    en-CA)
[✗] 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.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 2 categories.
johnsouza-loftbr commented 2 years ago

Hmmm. Can you copy the content of your Podfile here, please?

bhayatus commented 2 years ago
# Uncomment this line to define a global platform for your project
platform :ios, '14.0'

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

pod 'Analytics', '~> 4.1'

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__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
    end
  end
end
johnsouza-loftbr commented 2 years ago

Ok, right now I have two guesses:

  1. The problem is with Cocoapods. Running pod deintegrate and then pod install should fix;
  2. The problem is really about non-modular header, if it's that we'll need to release a new version of the library.

My guts points that option 1 will resolve, because I was unable to reproduce the problem, by updating to 3.9.0 and by using 3.9.0 on a new app.

Can you try that? I'm waiting for you answer on that.

bhayatus commented 2 years ago

Still not working. I'm reading online that newer versions of Xcode flag this as an issue, is it possible you are using an older version?

johnsouza-loftbr commented 2 years ago

Using the last stable release (13.4.1) here. Will create a new fork with some changes and reach you when it's ready for testing, ok?

bhayatus commented 2 years ago

Absolutely, I appreciate the speed of your replies.

johnsouza-loftbr commented 2 years ago

Just trying to help (and I don't like the ideia that someone's job is stuck because of me haha).

Just found something that can be helpful, last attempt to fix that without needing a new version of the plugin:

Add this line of code in your Podfile, inside post_install declaration:

config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'

So your Podfile will look like:

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

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

pod 'Analytics', '~> 4.1'

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__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
      config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
    end
  end
end
bhayatus commented 2 years ago

That worked, though seems like a band aid solution. Thanks for the fix in any case.

johnsouza-loftbr commented 2 years ago

Yay! And i agree with you, it's not the better solution, but at least you have your project working again.

I'll made the changes needed and when everything is good to go @danielgomezrico will release a new version, ok?

Thank you for you patience and help!

danielgomezrico commented 2 years ago

Is that something that must be done inside the library setup or that each client must do that on their personal podfile?

johnsouza-loftbr commented 2 years ago

@danielgomezrico I'm not 100% sure about the solution, maybe is the one that I described to @bhayatus. But my will is to solve inside the library, to avoid the need of adding something to the Podfile.

Right now I'm trying to reproduce the error, so can I start evaluating other solutions.

danielgomezrico commented 2 years ago

There's one way to cleanup your local dependencies on iOS:

        rm -rf ios/Pods/ || true
    rm ios/Podfile.lock || true

    flutter clean
    flutter pub get

    cd ios &&  pod repo update

Maybe that helps?

johnsouza-loftbr commented 2 years ago

@danielgomezrico thanks! Did that but the error still do not happen. @bhayatus have you tried to create a new flutter project, add the flutter_segment: 3.9.0 and run it on the iOS emulator?

bhayatus commented 2 years ago

So I tried a new Flutter project, and no issues running with 3.9.0. Then I decided to compare the Podfiles. Decided to remove the line pod 'Analytics', '~> 4.1' and the issue went away, even without the fix mentioned above. I'm not sure why the dependency was added originally (or why it causes the issue for that matter), since this plugin doesn't require that being there.

danielgomezrico commented 2 years ago

So @bhayatus we can close this issue?

bhayatus commented 2 years ago

I believe I should be good after making this change, thanks again.