firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
199 stars 32 forks source link

[Bug] iOS Build failure: '(any StorageProvider)?' must be unwrapped to refer #962

Closed shniqq closed 3 months ago

shniqq commented 3 months ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

Without changes from our side, we are now getting this build error for iOS:

❌  /Users/builder/clone/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.swift:73:12: value of optional type '(any StorageProvider)?' must be unwrapped to refer to member 'storage' of wrapped base type 'any StorageProvider'

    return provider.storage(for: Storage.bucket(for: app))
           ^

There seems to be other Firebase SDK affected, so seems like this needs to be fixed within this SDK too.

Steps to reproduce:

Reproduces 100% of the time, we started noticing yesterday. We're using Mac Mini M2 to build. Xcode 15.2.

Relevant Code:

Our podfile:

source 'https://cdn.cocoapods.org/'
source 'https://github.com/CocoaPods/Specs'

platform :ios, '15.2'

target 'UnityFramework' do
  pod 'AppLovinMediationByteDanceAdapter', '5.7.0.7.0'
  pod 'AppLovinMediationFacebookAdapter', '6.14.0.1'
  pod 'AppLovinMediationFyberAdapter', '8.2.5.2'
  pod 'AppLovinMediationGoogleAdapter', '10.14.0.1'
  pod 'AppLovinMediationGoogleAdManagerAdapter', '10.14.0.0'
  pod 'AppLovinMediationHyprMXAdapter', '6.3.0.0'
  pod 'AppLovinMediationIronSourceAdapter', '7.7.0.0.0'
  pod 'AppLovinMediationMintegralAdapter', '7.5.5.0.0'
  pod 'AppLovinMediationUnityAdsAdapter', '4.9.2.1'
  pod 'AppLovinMediationVungleAdapter', '7.2.1.0'
  pod 'AppLovinSDK', '12.1.0'
  pod 'FBSDKCoreKit', '~> 16.0.1'
  pod 'FBSDKCoreKit_Basics', '~> 16.0.1'
  pod 'FBSDKGamingServicesKit', '~> 16.0.1'
  pod 'FBSDKLoginKit', '~> 16.0.1'
  pod 'FBSDKShareKit', '~> 16.0.1'
  pod 'Firebase/Analytics', '10.15.0'
  pod 'Firebase/Auth', '10.15.0'
  pod 'Firebase/Core', '10.15.0'
  pod 'Firebase/Crashlytics', '10.15.0'
  pod 'Firebase/Database', '10.15.0'
  pod 'Firebase/Firestore', '10.15.0'
  pod 'Firebase/Functions', '10.15.0'
  pod 'Firebase/Messaging', '10.15.0'
  pod 'Firebase/RemoteConfig', '10.15.0'
  pod 'Firebase/Storage', '10.15.0'
  pod 'FirebaseAnalyticsOnDeviceConversion', '10.10.0'
  pod 'FirebaseInstallations'
  pod 'Google-Mobile-Ads-SDK', '~> 10.5'
  pod 'MolocoCustomAdapterAppLovin', '1.4.0.0'
end
target 'Unity-iPhone' do
end
use_frameworks!

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if ['MolocoSDKiOS-MolocoSDK', 'MolocoCustomAdapter-MolocoCustomAdapter', 'MolocoCustomAdapterAppLovin-MolocoCustomAdapterAppLovin', 'MolocoCustomAdapterIronSource-MolocoCustomAdapterIronSource'].include? target.name
        config.build_settings['CODE_SIGN_STYLE'] = 'Manual'
        config.build_settings['DEVELOPMENT_TEAM'] = ''
        config.build_settings['PROVISIONING_PROFILE_APP'] = ''
      end
    end
  end
end
najjarcm commented 3 months ago

I am facing the same issue in our project. I tried updating to SDK version 11.7.0 but still faced the same issue. In the end I changed all the Dependencies.xml files for all my components to use iosPod version 10.22.0 and the build worked.

Example of one of the dependencies.xml file in screenshot below. image

I am still unsure if that has any effects in the app, but initial testing shows that the build is working fine. Can probably use this as a quick fix until a correct fix is pushed from the SDK.

=EDIT= Please note that this solution was suggested in the other SDK (flutterfire) issues, and I just tried to mimic that in our project as well. Changing it for StorageDependencies.xml still gave me issues whiles trying to build so instead I increased them all to 10.22.0 and it worked afterwards.

nick-morhun commented 3 months ago

What could cause build failing without any changes in the source code?

najjarcm commented 3 months ago

Seems to be a native iOS library that got updated. That's what I understood from the comments on the other SDK issue thread.

Moomo commented 3 months ago

If you're encountering build issues in your Unity project due to a specific version in *Dependencies.xml files within the Library/PackageCache/com.google.firebase* directory, follow these simple steps to fix it:

  1. Open your terminal.
  2. Navigate to your Unity project's root directory.
  3. Run the following command:
    cd Library/PackageCache && find . -type f -name "*Dependencies.xml" -path "*com.google.firebase*" | xargs sed -i '' -e 's/10.15.0/10.22.0/g'

    This command finds *Dependencies.xml files containing the version 10.15.0 and replaces it with 10.22.0. Replace 10.15.0 with the version causing the build issues in your project.

paulinon commented 3 months ago

Thanks for bringing this to our attention, folks. I was able to reproduce the issue using the latest version of the Unity SDK. Another workaround you can do is manually update the iOS SDK version to 10.22.0 in the generated Podfile and run pod update.

That said, I'll be bringing this up with the team. You may refer to this thread for updates.

shniqq commented 3 months ago

Are all versions of the SDK affected by this?

marekmrva-ss commented 3 months ago

I can confirm SDK 11.3.0 is also affected

shniqq commented 3 months ago

What worked for us: Upgrade Firebase SDKs to 11.7.0

Add this script to set the iOS SDK to 10.22.0 as suggested:

public class FirebaseFixIosBuildPostProcessor : IPostprocessBuildWithReport
    {
        public int callbackOrder => int.MaxValue;

        public void OnPostprocessBuild(BuildReport report)
        {
            if (report.summary.platform != BuildTarget.iOS) return;

            string podfilePath = Path.Combine(report.summary.outputPath, "Podfile");

            if (File.Exists(podfilePath))
            {
                var podfileContent = File.ReadAllText(podfilePath);
                podfileContent = podfileContent.Replace("10.20.0", "10.22.0");
                File.WriteAllText(podfilePath, podfileContent);
            }
            else
            {
                Debug.LogWarning("Podfile not found in the Xcode project.");
            }
        }
    }

In our case, we also use Applovin Max for Ad mediation, we also needed to manually bump the Google Ads SDKs to 11.1.0.0, so we changed Dependencies.xml lines for MaxSdk/Mediation/Google/Editor/Dependencies.xml and MaxSdk/Mediation/GoogleAdManager/Editor/Dependencies.xml to

    <iosPods>
        <iosPod name="AppLovinMediationGoogleAdManagerAdapter" version="11.1.0.0" />
    </iosPods>
    <iosPods>
        <iosPod name="AppLovinMediationGoogleAdapter" version="11.1.0.0" />
    </iosPods>

respectively.

marekmrva-ss commented 3 months ago

Thank you for the great script @shniqq !

In case anybody is using UCB (or any other automatic building scripts) together with iOS Resolver, I suggest changing public int callbackOrder => int.MaxValue; to public int callbackOrder => 45; so that the iOS Resolver will use the patched pods

Source: https://github.com/googlesamples/unity-jar-resolver/blob/7a81c644a9f4e72db6cd0872aa138b4a667682c8/source/IOSResolver/src/IOSResolver.cs#L412

a-maurice commented 3 months ago

So, not sure what changed that caused this issue to start popping up, I imagine it was a change within XCode. But the latest release, 11.8.0, updates the iOS dependencies to 10.22.0, which will fix this issue.

Thanks for offering the scripts in the meantime as a workaround.

nick-morhun commented 3 months ago

We didn't change Xcode version recently.

shniqq commented 3 months ago

Us neither

Boronko commented 3 months ago

Instead of fixing the actual issue, you make us update the Firebase version? Please fix the old cocoa pods.

Whyser commented 3 months ago

Is there any fix to this other than upgrading the Firebase SDK? I'm having issues with the new version and would need to stay on old version for now. @paulinon

georgemarkosian commented 3 months ago

After some back and forth we figured out the only 2 ways to make our app compile:

  1. Leave 11.6.0 and remove the Cloud Storage component from the project
  2. Update to 11.8.0 and remove Firestore

None of those are livable as our app relies on both. While discovering it we tried different versions of xCode (15.0.1, 15.1, 15.2, 15.3) and Unity (2022.3.20, 2022.3.22). We also tried removing other plugins with native components (FacebookSDK, AppsFlyer, GoogleSignIn) - no difference. We also tested another app we have that works without Firebase, it's ok.

We believe the issue lies in Firebase and hope it will be resolved soon. It affects our business as we can't produce builds and test the upcoming app update.

Update 1: tried updating cocoaPods version to 10.23 => results in Undefined symbols errors.