Carthage derived cache issue when switching xcode-select

Created on 14 Jul 2017  路  18Comments  路  Source: Carthage/Carthage

  • carthage version: 0.24.0
  • xcodebuild -version: XCode 9 Beta 3: 9M174d
  • Are you using --no-build? No
  • Are you using --no-use-binaries? Yes
  • Are you using --use-submodules? No
  • Are you using --cache-builds? Yes
  • Command: carthage update --no-use-binaries --platform iOS --cache-builds

Highlight

When building using Carthage in an newer version of xcodebuild, Carthage builds the new framework but reaches this error (Full output below):
error: module compiled with Swift 3.1 cannot be imported in Swift 3.2
OR
error: module compiled with Swift 3.1 cannot be imported in Swift 4.0

The Carthage directory in the project is deleted before running Carthage:
rm -rf Carthage

The problem occurs with a framework building against a dependent framework. FrameworkA builds. FrameworkB builds and has an import FrameworkA in the code. xcodebuild claims Framework A has this issue: error: module compiled with Swift 3.1 cannot be imported in Swift 3.2

Other colleagues are also having this issue so it is not isolated to just myself.

The only current fix is to delete Carthage DerivedData:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData

Carthage Output:

* Fetching FrameworkA
Fetching FrameworkB
Checking out FrameworkA at "v0.2.0"
Checking out FrameworkB at "v2.2.2"
No cache found for FrameworkA, building with all downstream dependencies
No cache found for FrameworkB, building with all downstream dependencies
xcodebuild output can be found in /var/folders/fg/xxx/T/carthage-xcodebuild.N10dNu.log
Building scheme "FrameworkA" in FrameworkA.xcodeproj
*
* Building scheme "FrameworkB" in FrameworkB.xcodeproj

Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/xxx/Carthage/Checkouts/FrameworkB/FrameworkB.xcodeproj -scheme xxx -configuration Release -derivedDataPath /Users/xxx/Library/Caches/org.carthage.CarthageKit/DerivedData/FrameworkB/v2.2.2 -sdk iphonesimulator -destination platform=iOS\ Simulator,id=xxx -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/xxx/Carthage/Checkouts/FrameworkB)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/fg/lgm04jdn7hgckxhc0r88c24ssydyh0/T/carthage-xcodebuild.jUcRMX.log

Log output (/var/folders/fg/lgm04jdn7hgckxhc0r88c24ssydyh0/T/carthage-xcodebuild.jUcRMX.log):

/Users/xxx/Carthage/Checkouts/FrameworkB/xxx.swift:2:8: error: module compiled with Swift 3.1 cannot be imported in Swift 3.2: /Users/xxx/Carthage/Checkouts/FrameworkB/Carthage/Build/iOS/FrameworkA.framework/Modules/FrameworkA.swiftmodule/x86_64.swiftmodule
import FrameworkA
^

* BUILD FAILED *

The following build commands failed:
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64

Most helpful comment

I had a similar issue, but the other way around. Problem was for me, that I tried building in Xcode 8 (after once building for Xcode 9) for that I removed the Carthage folder, but it didn't help. I received a 'cannot import framework build with Swift 4 in Swift 3.1' error.

But running rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData AND removing the Carthage folder fixed the issue.

All 18 comments

* Building scheme "FrameworkA" in FrameworkA.xcodeproj
*
Building scheme "FrameworkB" in FrameworkB.xcodeproj

If FrameworkA depends on FrameworkB the build order seems odd. Are you sure that FrameworkB is listed in FrameworkA's Cartfile?

I may see the old content before you edited.

Or maybe you are committing Carthage/Build/FrameworkA.framework in FrameworkB repo which was built with Swift 3.1 and Xcode tries to use the framework.

The main application and all frameworks are separate repositories. Only cartfile and cartfile.resolved are committed to each repository. I have 14 frameworks and have been running Carthage since Swift 2 beta without this issue.

My best guess is it could be an issue with me switching from XCode 8.3.3 to 9 beta 1, 2, and then 3. Clearing the Carthage derived data was the only solution on 2 separate occasions for myself. A colleague using different frameworks had the same issue and came to the same solution after exhausting all other options.

I have both XCode 8 and 9 installed but XCode 9 is selected and the only GUI running.

We can dig it if you could provide example (or actual) repositories those reproduce the problem you are facing.

Unfortunately they are all private repositories. I was hoping someone could +1 this issue and provide a similar experience.

I had a similar issue, but the other way around. Problem was for me, that I tried building in Xcode 8 (after once building for Xcode 9) for that I removed the Carthage folder, but it didn't help. I received a 'cannot import framework build with Swift 4 in Swift 3.1' error.

But running rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData AND removing the Carthage folder fixed the issue.

Hmm so this may be the consequence of #2053.

cc @BobElDevil

I too ran into this, sometime around upgrading carthage 0.23.0 -> 0.24.0 and switch back and forth between XCode 9 Beta 3 and XCode 8.

Hmm, yes #2053 may be the culprit. Since we don't clean the sim build (only device), it's using stale frameworks if the code isn't considered 'changed' and skips rebuilding, but the xcode switch occurred, so it's still incompatible

What should have been done is a clean for both sim and device _first_, then build-only for both in a row, to fix the original issue that #2053 was for, while not leaving behind stale frameworks. I'll look into fixing this up shortly

Had the same problem with an added layer of complexity. I have Xcode 9 installed via xcversion gem. xcode-select -p showed the path to the normal Xcode version (8.3.2 for me). I ran (by accident) carthage update on our repo. It seemed to use Xcode 9 and build for Swift 4. We normally run carthage bootstrap --platform ios --cache-builds --toolchain com.apple.dt.toolchain.Swift_3_1 when bootstrapping or updating. So lyft/mapper was accidentally built with Swift 4 and I tried rebuilding with the toolchain argument which didn't help. Eventually saw the cache dir in the build command and was able to rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData and rm -rf Carthage/{Build,Checkouts}/

@acrookston We are invoking xcodebuild commands through /usr/bin/xcrun. So that gem may not support that way.

Closed by #2102.

@ikesyo Thanks for the fix.

The gem just changes the path via xcode-select so nothing fancy going on with the gem. Any way you install Xcode 9, I believe the problem would still persist.

@ikesyo do you agree it would be useful to add

 rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData

in the README/FAQ?

I was lucky I found this closed issue to know the command for the cache.

Maybe #2102 is enough, but I don't know

I'm not seeing this issue with Xcode 9.1 and Swift 4.0.2. Oddly only with one framework Hearst-DD/ObjectMapper and only on BuildKite (it compiles fine locally):

module compiled with Swift 4.0 cannot be imported in Swift 4.0.2: /Users/<name>/<project_name>-ios/Carthage/Build/iOS/ObjectMapper.framework/Modules/ObjectMapper.swiftmodule/x86_64.swiftmodule

I've tried cleaning the builds, derived data for both Carthage and Xcode and removing the Carthage directory entirely to rebuild everything.

The .frameworks are checked into the repo and not rebuilt on by the CI pipeline, but instead linked directly from the Carthage/Builds/iOS directory.

Anyone have an idea or suggestion for me?

@runmad I have exactly the same problem with you, did you find the solution?

@ioio007 do you have multiple toolchains installed?

@racer1988 no, but I finally found the problem, I just do all the action in another folder...

Was this page helpful?
0 / 5 - 0 ratings