googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.22k stars 339 forks source link

[Bug] Build for iOS Simulator doesn't compile in Debug mode #512

Open marekzd opened 2 years ago

marekzd commented 2 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

Build for iOS Simulator doesn't compile in Debug mode.

XCode throws the following error:

ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/AppAuth'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GTMAppAuth'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GTMSessionFetcher'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GoogleSignIn'
ld: framework not found AppAuth
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here are steps to reproduce this:

  1. Create a new Unity Project
  2. Install EDM4U
  3. Add Editor/Dependencies.xml file
    <dependencies>
        <iosPods>
            <iosPod name="GoogleSignIn" version="~> 6.0"/>
        </iosPods>
    </dependencies>
  4. Open Project Settings / Player and set iOS Target to Simulator SDK
  5. Open Build Settings... and switch to iOS platform
  6. Set Run in XCode as to Debug
  7. Click on Build and Run
  8. Unity export succeeds, but XCode compilation fails with error: framework not found AppAuth
  9. It works fine after switching to Release mode

Please answer the following, if applicable:

What's the issue repro rate? (eg 100%, 1/5 etc) 100%

What happened? How can we make the problem occur?

Unity enforces x86_64 architecture for Unity-iPhone and UnityFramework targets (ARCHS=x86_64).

It seems that XCode is not able to build pods in x86_64 architecture in Debug mode. Although it can do that in Release mode.

I'm not sure why that happens.

It might be related to Build Active Architecture Only being set for Debug builds. It also might be related to Apple M1.

Here you can find a sample project: EDM4UiOSSimulatorDebugBug.zip

google-oss-bot commented 2 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

chkuang-g commented 2 years ago

According to your description, I have a feeling that this is an issue with GoogleSignIn iOS pod, since you are using an empty project with a single Dependencies.xml file. What EDM4U does is basically generating a Podfile under the Xcode project and run pod install.

But before I jump into conclusion, I would like to learn a bit more about your situation.

  1. Did you see Podfile under the exported Xcode project? What is the content?
  2. Did you open Xcode project using Unity-iPhone.xcworkspace? Does it exist under your Xcode project folder?
marekzd commented 2 years ago

Did you see Podfile under the exported Xcode project? What is the content?

Yes, here you have it:

source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'UnityFramework' do
  pod 'GoogleSignIn', '~> 6.0'
end
target 'Unity-iPhone' do
end
use_frameworks! :linkage => :static

Did you open Xcode project using Unity-iPhone.xcworkspace? Does it exist under your Xcode project folder?

Unity opened Unity-iPhone.xcworkspace for me after clicking on Build and Run.

Yes, Unity-iPhone.xcworkspace exists under my Xcode project folder.

I have a feeling that this is an issue with GoogleSignIn iOS pod, since you are using an empty project with a single Dependencies.xml file.

I've tried with the following Dependencies.xml file:

<dependencies>
    <iosPods>
        <iosPod name="Firebase/RemoteConfig" version="~> 8.15"/>
    </iosPods>
</dependencies>

and the problem is the same.

What EDM4U does is basically generating a Podfile under the Xcode project and run pod install.

I think that the project generated by Cocoapods doesn't cope well with ARCH=x86_64 enforced by Unity.

It looks like XCode build system in Debug mode assume that pods don't support x86_64 and don't build them. It only builds UnityIPhone UnityFramework targets.

(I'm using XCode 13.3.1 by the way)

Unfortunately, I don't get how XCode build system plans its buidling...

chkuang-g commented 2 years ago

Unity opened Unity-iPhone.xcworkspace for me after clicking on Build and Run.

Eh, Unity actually does NOT know about xcworkspace. That is generated by Cocoapod which is not officially supported by Unity yet. That is what EDM4U comes to resolve this. My think Unity is actually opening Unity-iPhone.xcodeproj which may not contain all the frameworks added by Cocoapod.

Try to open Xcode project using Unity-iPhone.xcworkspace and see if you still have the issue.

marekzd commented 2 years ago

My think Unity is actually opening Unity-iPhone.xcodeproj which may not contain all the frameworks added by Cocoapod.

This works fine on my side - Unity opens xcworkspace after clicking [Build and Run].

Here you have a screen of XCode window, that shows up after clicking on [Build and Run]:

XCode screenshot

Try to open Xcode project using Unity-iPhone.xcworkspace and see if you still have the issue.

I opened Unity-iPhone.xcworkspace manually and it didn't help.

I've also tried opening Unity-iPhone.xcodeproj and you are right, it creates the same problem.

So yeah, I have to admit that my problem is similar, though on xcworkspace and only in Debug mode 😄

I have one more observation: \ Build succeeds when I set Pods project / Build settings / Build Active Architecture Only / Debug to No.

chkuang-g commented 2 years ago

Hi @marekzd

Could you try something for me? Just like to narrow down the issue.

marekzd commented 2 years ago

Could you try something for me? Just like to narrow down the issue.

Yes, it results in the same error:

ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/AppAuth'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GTMAppAuth'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GTMSessionFetcher'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-dvncmapbtllnstgjcbjcurdvibwh/Build/Products/Debug-iphonesimulator/GoogleSignIn'
ld: framework not found AppAuth
chkuang-g commented 2 years ago

I see. In that case, I think this can be a potential issue in GoogleSignIn pod.

I would transfer your issue to their repo so that they can take it from here.

chkuang-g commented 2 years ago

Alright. Seems like I cannot transfer to https://github.com/google/GoogleSignIn-iOS/issues

Here is my recommendation:

  1. Go to https://github.com/google/GoogleSignIn-iOS/issues and report an issue
  2. Prepare a minimal viable Xcode project for them
    1. Create an Xcode project generated by an empty Unity project.
    2. Add the Podfile to the project.
  3. Give them instruction and configuration (ex. Xcode version) to repro the issue
  4. Reference this thread in the post.

Thank you

marekzd commented 2 years ago

I think this can be a potential issue in GoogleSignIn pod.

I don't think so.

I think the problem is not related to any specific package.

I've tried adding Firebase/RemoteConfig or SDWebImage instead of GoogleSignIn and the problem remained.

I've also tried removing all dependencies and built with the following Podfile:

source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'UnityFramework' do
end
target 'Unity-iPhone' do
end
use_frameworks! :linkage => :static

and it also failed with similar error:

ld: framework not found Pods_UnityFramework

I think the problem lies in Unity-iPhone and Unity-Framework strange simulator project configuration, Cocoapods inability to cope with that configuration and probably with Apple M1 building environment too.

Did you try to reproduce this bug on your side ?

chkuang-g commented 2 years ago

Hmm, it is odd that Firebase/RemoteConfig does not work for you.

I tried to build Firebase Analytics Quickstart with Unity 2020.3.18f1.

Then I tried the project you provided. I was still able to build successfully. Screen Shot 2022-06-14 at 6 18 00 PM

So...this does not seems to be an issue related to either those pods or EDM4U.

Perhaps upgrade Xcode version and see if that works for you?

google-oss-bot commented 2 years ago

Hey @marekzd. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

marekzd commented 2 years ago

I've upgraded XCode to v13.4.1 (13F100).

I've tried the project that I provided and debug build failed with the same linker error as previously.

I've also tried building Firebase Analytics Quickstart following your instructions and it also failed in debug mode and throwing similar error:

ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/FirebaseCore'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/FirebaseCoreDiagnostics'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/FirebaseCoreInternal'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/FirebaseInstallations'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/GoogleDataTransport'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/GoogleUtilities'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/PromisesObjC'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/nanopb'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FirebaseAnalytics/AdIdSupport'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/GoogleAppMeasurement/AdIdSupport'
ld: warning: directory not found for option '-F/Users/marekzd/Library/Developer/Xcode/DerivedData/Unity-iPhone-eufhbklrshjckfetsaksyhbltqrw/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/GoogleAppMeasurement/WithoutAdIdSupport'
ld: framework not found FBLPromises
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Did you build on Apple M1 computer ?

marekzd commented 2 years ago

I think the problem lies in how Unity configures XCode project and Cocoapods being unable to cope with that on Apple M1.

I was curious whether something changed in newer versions of Unity and I tested my example on Unity v2021.3.5f1 with Cocoapods v1.11.3, but the problem is still there.

a-maurice commented 2 years ago

I have been able to reproduce this problem on an Apple M1, so I do think that is indeed the problem, and this does only seem to occur when building for Simulator, and Debug. It seems that it is likely a weird interaction with Unity, XCode, and Cocoapods, and we will see if there is a workaround we can implement. Trying suggestions that I have found on similar issues has not resulted in any success yet, unfortunately.