Subito-it / PodBuilder

A tool to precompile CocoaPods pods
Other
284 stars 28 forks source link

Any way to get rid of "Module compiled with Swift X.X cannot be imported by Swift X.X compiler" error? #64

Closed hardeverick closed 1 year ago

hardeverick commented 2 years ago

Hi,

Every time I update Xcode I get this error and I have to manually specify the Swift version for some pods to match the Swift compiler in the version of Xcode I'm using. I looked online and this answer suggests setting the option BUILD_LIBRARY_FOR_DISTRIBUTION but it doesn't seem to work.

This is my Podbuilder.json file

{
  "project_name": "HAR",
  "spec_overrides": {
    "Google-Mobile-Ads-SDK": {
      "module_name": "GoogleMobileAds"
    },
    "glog": {
      "pod_target_xcconfig": {
        "DEFINES_MODULE": "NO"
      }
    },
    "DoubleConversion": {
      "pod_target_xcconfig": {
        "DEFINES_MODULE": "NO"
      }
    },
    "Folly": {
      "pod_target_xcconfig": {
        "DEFINES_MODULE": "NO"
      }
    },
    "Flipper-DoubleConversion": {
      "pod_target_xcconfig": {
        "DEFINES_MODULE": "NO"
      }
    },
    "Flipper-Folly": {
      "pod_target_xcconfig": {
        "DEFINES_MODULE": "NO"
      }
    },
    "AlignedCollectionViewFlowLayout": {
      "swift_version": "5.6"
    },
    "RealmSwift": {
      "swift_version": "5.6"
    },
    "SwiftHash": {
      "swift_version": "5.6"
    },
    "SwiftSimplify": {
      "swift_version": "5.6"
    },
    "FloatingPanel": {
      "swift_version": "5.6"
    },
    "ActiveLabel": {
      "swift_version": "5.6"
    }
  },
  "skip_licenses": [

  ],
  "skip_pods": [
    "GoogleMaps",
    "React-RCTFabric",
    "React-Core",
    "React-CoreModules"
  ],
  "force_prebuild_pods": [

  ],
  "build_settings": {
    "ENABLE_BITCODE": "NO",
    "GCC_OPTIMIZATION_LEVEL": "s",
    "SWIFT_OPTIMIZATION_LEVEL": "-Osize",
    "SWIFT_COMPILATION_MODE": "wholemodule",
    "CODE_SIGN_IDENTITY": "",
    "CODE_SIGNING_REQUIRED": "NO",
    "CODE_SIGN_ENTITLEMENTS": "",
    "CODE_SIGNING_ALLOWED": "NO",
    "BUILD_LIBRARY_FOR_DISTRIBUTION": "YES"
  },
  "build_settings_overrides": {
    "SBTUITestTunnelClient": {
      "ENABLE_BITCODE": "NO"
    }
  },
  "build_system": "Latest",
  "library_evolution_support": false,
  "license_filename": "Pods-acknowledgements",
  "restore_enabled": true,
  "allow_building_development_pods": false,
  "use_bundler": false,
  "deterministic_build": false,
  "build_using_repo_paths": false,
  "react_native_project": false
}
tcamin commented 2 years ago

Hi, instead of setting "BUILD_LIBRARY_FOR_DISTRIBUTION": "YES" you should set "library_evolution_support": true (see https://github.com/Subito-it/PodBuilder#library_evolution_support).

In general however I would advise to set "build_xcframeworks_all": true (which implies library evo support) which will produce xcframeworks adding Apple Silicon support

hardeverick commented 2 years ago

Thanks for the reply @tcamin

I tried this and I'm no longer getting the cannot be imported error, but I'm getting a lot these errors (see screenshot below):

image

is there anything else I'm doing wrong?

Thanks

hardeverick commented 2 years ago

@tcamin It seems like this is caused because the Module and class name are the same according to this https://developer.apple.com/forums/thread/123253. There's a proposed fix in that link that runs this command find . -name "*.swiftinterface" -exec sed -i -e 's/frameworkName\.//g' {} \;. Is there something similar that I could run in PodBuilder?

hardeverick commented 2 years ago

In the mean time I worked around the problem by switching the pods with problems to use SPM (Swift Package Manager).

tcamin commented 2 years ago

You should be able to patch the switfinterface files by adding this to your Podfile

post_install do |installer|
  swift_interface_paths = Dir.glob("./PodBuilder/Prebuilt/RealmSwift/**/*.swiftinterface")
  swift_interface_paths.each do |path|
      content = File.read(path)
      content.gsub!("Realm.RLM", "RLM")
      content.gsub!("Realm.Realm", "Realm")
      File.write(path, content)
  end
end

With respect to your workaround of using SPM you could alternatively just add the non working pods to the skip list as documented here