Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v10.49.3 failing to Build after updating using SPM.error: "but cannot be built dynamically because there is a package product with the same name." #8566

Closed
arsh94deep opened this issue May 2, 2024 · 11 comments

Comments

@arsh94deep
Copy link

How frequently does the bug occur?

Always

Description

Overview
I was using Cocoapods for integrating relm.
after updating to xcode 15.3
I removed the cocoapods properly and integrated Realm using Swift Package Manager.
I have installed the Version v10.49.3 of the realm-swift package.
as soon as I try to build the project I get an error :-

Error Message
"Build failed: Swift package target 'Realm' is linked as a static library by 'TeddyTonk' and 'Realm', but cannot be built dynamically because there is a package product with the same name."

1.Goals
successfully Integrate realm-swift in xcode 15.3 using SPM.

2.Expected results
The project to Build Properly.

3.Actual results
Unable to Build the project.

4.Steps to reproduce
Install realm- swift v10.49.3 using SPM in xcode 15.3.
build the project.

5.Versions
Xcode - 15.3
realm-swift - v10.49.3
Mac OS - 14.4.1

6.Dependency manager used
Swift Package manager

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

STEP 1: Install realm- swift v10.49.3 using SPM in xcode 15.3.
STEP 2: build the project.

Version

v10.49.3

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Xcode - 15.3, realm-swift - v10.49.3, Mac OS - 14.4.1

Build environment

Xcode version: 15.3
Dependency manager and version: SPM

Copy link

sync-by-unito bot commented May 2, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2346

@bweissmann
Copy link

bweissmann commented May 2, 2024

Edit

As explained by @nirinchev below, we needed to remove an explicit dependency on Realm in our targets and we've now resolved this.

This was an unexpected dev experience for us since we hadn't touched Realm in a number of years weren't anticipating a breakage of this kind.

Original

+1 All of our builds on MS AppCenter started consistently failing a few days ago with this error, downgrading Realm to 10.33.x seemed to help

Here are snippets from our AppCenter configuration logs if it helps with a repro

##[group]Runner Image
Image: macos-13
Version: 20240421.1
Included Software: https://github.com/actions/runner-images/blob/macos-13/20240421.1/images/macos/macos-13-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macos-13%2F20240421.1
##[endgroup]
##[group]Runner Image Provisioner
2.0.369.1+55cddbb57f254a369b6e7b3b508cebdbee5d24be
##[endgroup]
Current image version: '20240421.1'
Agent running as: 'runner'
Prepare build directory.
Set build variables.
Download all required tasks.
Downloading task: PowerShell (2.237.5)
Downloading task: ShellScript (2.238.1)
Downloading task: CmdLine (1.1.3)
Downloading task: InstallAppleCertificate (2.238.1)
Downloading task: InstallAppleProvisioningProfile (0.124.0)
Downloading task: Xcode (4.130.0)
Downloading task: CopyFiles (2.238.0)
Downloading task: PublishBuildArtifacts (1.238.1)
Downloading task: AppCenterDistribute (3.238.1)

...
2024-05-02T18:36:32.6509830Z Checking out 10.48.2 of package ‘realm-swift’
...
2024-05-02T18:36:38.3806010Z Checking out 13.26.0 of package ‘realm-core’
...
2024-05-02T18:37:34.3812330Z   RealmDatabase: https://github.com/realm/realm-core.git @ 13.26.0
...
2024-05-02T18:37:43.3460750Z         ➜ Explicit dependency on target 'RealmSwift' in project 'Realm'
2024-05-02T18:37:43.3462290Z         ➜ Explicit dependency on target 'Realm' in project 'Realm'
2024-05-02T18:37:43.3464180Z         ➜ Explicit dependency on target 'RealmCore' in project 'RealmDatabase'
...
2024-05-02T18:38:05.3798750Z error: Swift package target 'Realm' is linked as a static library by 'APPNAME' and 'Realm', but cannot be built dynamically because there is a package product with the same name.

@nirinchev
Copy link
Member

I believe this exact error message is covered in the release notes of 10.49.3: https://github.com/realm/realm-swift/releases/tag/v10.49.3

Have you made sure that your targets only depend on RealmSwift or Realm?

@nirinchev
Copy link
Member

The motivation behind this change is laid out in this PR: #8561. We agree that this is not ideal DX, but it's the best we could come up under the circumstances (Apple requiring a privacy manifest for Realm, while Xcode not merging the privacy manifests for static frameworks correctly).

@Kalzem
Copy link

Kalzem commented May 2, 2024

Someone at Realm frontend might want to edit the official documentation on the website : https://www.mongodb.com/docs/atlas/device-sdks/sdk/swift/install/#installation.

It stills says

4 - Select the Package Products
Select both Realm and RealmSwift, then click Add Package.

@nirinchev
Copy link
Member

Yes, we have it on our todo list - in this case we had to rush the release out to comply with Apple's May 1st deadline.

@dacharyc
Copy link
Contributor

dacharyc commented May 2, 2024

I think you're seeing a cached version - if you reload the page, you should see that this has been updated:

4 - Select the Package Products
Changed in version 10.49.3: Instead of adding both, only add one package.

Select either RealmSwift or Realm, then click Add Package.

  • If you use Swift or Swift and Objective-C APIs, add RealmSwift.
  • If you use only Objective-C APIs, add Realm.

@nirinchev
Copy link
Member

Thanks @dacharyc, I can confirm after force reloading the page I see the updated instructions:

Screenshot 2024-05-02 at 23 26 38

@lluisgerard
Copy link

How do you deal with this with Realm dependencies? I've been dealing with this issue for a few hours now in a big project with lots of dependencies and no matter what I do I always get the error "Swift package target 'Realm' ... cannot be built dynamically because there is a package product with the same name.".

For instance, I just created a new project from scratch and the only thing that I did is to add RxRealm https://github.com/RxSwiftCommunity/RxRealm:

And the error appears (the project is called "realm-rxrealm"):
image

RxRealm installed these dependencies:
image

And the only library is RxRealm:
image

I cannot add Realm or RealmSwift as a dynamic framework because it doesn't appear:
image

Is this something that RxRealm should handle or am I missing something?

Another thing I tried is to add RealmSwift to the project alongside RxRealm:
image
image

But the error keeps appearing. I created a separate project only with RealmSwift and I get no errors. So I assume something needs to be changed in RxRealm project.

Their Swift.package has all these:

.target(name: "RxRealm",
    dependencies: [
        .product(name: "RxSwift", package: "RxSwift"),
        .product(name: "Realm", package: "Realm"),
        .product(name: "RealmSwift", package: "Realm"),
        .product(name: "RxCocoa", package: "RxSwift")
    ],
path: "Sources"),

Am I right in thinking that .product(name: "Realm", package: "Realm"), is the problem here?

@lluisgerard
Copy link

lluisgerard commented May 3, 2024

Update on dependencies (see previous message):

I forked RxRealm and I removed "Realm" but kept "RealmSwift" on every target and removed it from Package.swift. This solved the issue and I get no errors now.

Inside the library "RealmSwift" is marked as "Do Not Embed". So I assume that I will have to manually supply the Manifest myself in my project.

@anton-plebanovich
Copy link

Thank you @lluisgerard 👍

The error message is confusing. I would probably spend hours trying to figure that out myself without realizing it is due to other dependencies that depend on Realm

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants