e-mission / e-mission-docs

Repository for docs and issues. If you need help, please file an issue here. Public conversations are better for open source projects than private email.
https://e-mission.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
15 stars 34 forks source link

XCode and `osx-build-ios` CI need updating #1060

Closed the-bay-kay closed 3 months ago

the-bay-kay commented 8 months ago

The Issue

Currently, our ios-build CI (link) uses XCode 14.2. On this version of xcode, the build scripts run (link) as intended.

When updating to XCode 15+, npm run build-dev-ios fails with the following error:

// more warnings above
/Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target 'FirebaseCore' from project 'Pods')
/Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target 'Bolts' from project 'Pods')
/Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target 'GoogleUtilities' from project 'Pods')
/Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/CordovaLib/CordovaLib.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 11.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target 'CordovaLib' from project 'CordovaLib')
/Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target 'PromisesObjC' from project 'Pods')
** BUILD FAILED **

The following build commands failed:
    Ld /Users/{User}/Documents/OpenPATH_Repos/e-mission-phone-working/platforms/ios/build/emulator/Bolts.framework/Bolts normal (in target 'Bolts' from project 'Pods')
(1 failure)
xcodebuild: Command failed with exit code 65

As we can see in the CI, the target warnings are expected. However, in XCode 15+, these warnings result in a failstate. This thread goes into greater detail as to why this is the case.

Temporary Fix

For those on a MacOS version below 14.0, one can simply download and downgrade to XCode 14.2. Unfortunately, it appears that this version of XCode is not compatible with the MacOS Sonoma:

image

For those working with XCode 15+, please see my build instructions detailed in this PR. I am currently exploring alternatives to this: if I can find a way to get XCode to install command-line tools below 15, they could be changed within the settings as seen here:

image

Long Term Plans

Within the next few months, we will need to:

  1. Update the CI, so that it uses XCode 15+
  2. Update the build scripts for XCode, such that the build targets are increased. a. This comment in the stack overflow thread suggests a method of doing this that may be worth exploring.
  3. The Build documentation within the e-mission-phone readme may need to be updated, to include the new version requirement
  4. Once this change is made, the team will need to update their XCode versions to 15.0+
the-bay-kay commented 8 months ago

Currently attempting this method of retrofitting iOS 14 to work on Sonoma. My first attempt did let me run XCode, but our build script did not recognize the installation. Attempting a fresh install, tweaking some small things, will update this post accordingly!

EDIT: No dice, still hit with the same "Build Target" error as described above. Looking for other ways to expedite the build process, will keep this thread updated as I find fixes!

shankari commented 7 months ago

We all need to upgrade to xcode 15 now because

ITMS-90725: SDK version issue - This app was built with the iOS 16.1 SDK. Starting April 29, 2024, all iOS and iPadOS apps must be built with the iOS 17 SDK or later, included in Xcode 15 or later, in order to be uploaded to App Store Connect or submitted for distribution.

shankari commented 7 months ago

I just worked around this by forcing the use of xcode 14. The migration to xcode 15 is still open. @louisg1337 this is the issue on the upgrade

shankari commented 7 months ago

The error that I actually got in the CI was (https://github.com/e-mission/e-mission-phone/pull/1148#issuecomment-2079688203)

clang: error: SDK does not contain 'libarclite' at the path '/Applications/Xcode_15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a'; try increasing the minimum deployment target

which seems to be due to the deployment target https://stackoverflow.com/a/77144603

While it is possible to set the deployment target manually in xcode, we can also set it in the config.xml https://stackoverflow.com/a/76483154

That should set the IPHONEOS_DEPLOYMENT_TARGET that we are complaining about here From platforms/ios/cordova/lib/prepare.js,

    if (deploymentTarget) {
        events.emit('verbose', `Set IPHONEOS_DEPLOYMENT_TARGET to "${deploymentTarget}".`);
        project.xcode.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget);
    }

That is necessary, but I am not sure if it will be sufficient. Concretely, there are multiple matches for IPHONEOS_DEPLOYMENT_TARGET in ./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj and they are not all the same.

$ grep -r IPHONEOS_DEPLOYMENT_TARGET .
....
./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 9.0;
./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 10.0;
./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 9.0;
./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 9.0;
./platforms/ios/Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 11.0;

I think these are being added by the individual Podfiles. There is a workaround to modify the Podfile to fix that https://stackoverflow.com/a/77513296

But the platforms/ios/Podfile is autogenerated in our case, so we can't edit it manually.

@louisg1337, I would suggest the following steps:

  1. Get the build to work with XCode 14 so you are starting from a "working" state
  2. Upgrade to XCode 15 (build should break)
  3. Try setting the deploymentTarget in config.xml and see if it fixes the build
  4. If not, try to figure out how to modify the Podfile in cordova (I suspect it is the config-file entry in the config.xml, like the current `

Once you get it to build successfully on your local laptop, submit a PR that includes: i. your change, ii. changes to the settings in .github/workflows/ios-build.yml to use OSX 14 and xcode 15

LMK if you have any questions

louisg1337 commented 6 months ago

Xcode Upgrade Update

I've been playing around with this the past few days and have thankfully managed to get the project to build using Xcode 15 (PR here). I've tried a few different ways to solve this problem, which I will get into later, but the final working solution ended up being a before_build hook that manually finds each pod dependency and updates its minimum deployment. I was lucky enough to find an issue which depicted the same problem we were facing, and someone provided their script to fix it.

It isn't the cleanest fix to the problem, but it doesn't seem like there is any other way to fix it right now. Earlier in the thread, the devs said to ignore the deployment warning as it didn't matter with Xcode 14. Since it now just recently went from a warning to an error in Xcode 15, it seems like we are out of luck for the time being until they figure out a way forward. I'll definitely keep an eye on their issue board to see if it gets solved in the near future.

Other Attempted Solutions

Before finding that thread, I tried a few other things first. I first tried setting the deploymentTarget in config.xml. That correctly set the deployment version of emission to 12.0, but it didn't do it for any of the pods. One of the maintainers of cordova also stated that it wasn't meant to be used for the pods here.

The next thing I tried was to modify the Podfile with the code mentioned above in this StackOverflow. Now there is a way to add to the Podfile in the plugin.xml of a plugin using podspec. However, this only allows you to add pods and doesn't give us the flexibility we need to write the code above. I then tried creating a before_build script that would add that code to the Podfile, and while it got added, the Podfile never executed that code. I then went down a rabbit hole of trying to figure out how to re-run the Podfile using pod install, but I ran into a lot of issues figuring out how to run pod commands with the local installation setup we have. That was when I eventually stumbled upon the issue I mentioned above, which gave us our solution.

shankari commented 6 months ago

Note that the most recent version of xcode (15.3) requires OSX 14 or later. I'm currently upgrading to XCode 15.0.1, which still supports OSX 13.5 and will upgrade to OSX 14 and XCode 15.3 later.

But this works on CI/CD so optimistically closing this unless I run into some issues with either of the two steps later.

shankari commented 6 months ago

After implementing step 1, the builds are fine, but alas, archive fails

PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/kshankar/Library/Developer/Xcode/DerivedData/NREL_OpenPATH-elockvrbyntkapgkvnvqftzmkpzt/Build/Intermediates.noindex/ArchiveIntermediates/NREL\ OpenPATH/IntermediateBuildFilesPath/NREL\ OpenPATH.build/Release-iphoneos/NREL\ OpenPATH.build/Script-894D1DEC9B25B55F1D0A2B0A.sh (in target 'NREL OpenPATH' from project 'NREL OpenPATH')
    cd /Users/kshankar/Desktop/data/in-house/openpath-phone/platforms/ios
    /bin/sh -c /Users/kshankar/Library/Developer/Xcode/DerivedData/NREL_OpenPATH-elockvrbyntkapgkvnvqftzmkpzt/Build/Intermediates.noindex/ArchiveIntermediates/NREL\\\ OpenPATH/IntermediateBuildFilesPath/NREL\\\ OpenPATH.build/Release-iphoneos/NREL\\\ OpenPATH.build/Script-894D1DEC9B25B55F1D0A2B0A.sh

mkdir -p /Users/kshankar/Library/Developer/Xcode/DerivedData/NREL_OpenPATH-elockvrbyntkapgkvnvqftzmkpzt/Build/Intermediates.noindex/ArchiveIntermediates/NREL OpenPATH/BuildProductsPath/Release-iphoneos/NREL OpenPATH.app/Frameworks
Symlinked...
rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Bolts.framework" "/Users/kshankar/Library/Developer/Xcode/DerivedData/NREL_OpenPATH-elockvrbyntkapgkvnvqftzmkpzt/Build/Intermediates.noindex/ArchiveIntermediates/NREL OpenPATH/InstallationBuildProductsLocation/Applications/NREL OpenPATH.app/Frameworks"
building file list ... rsync: link_stat "/Users/kshankar/Desktop/data/in-house/openpath-phone/platforms/ios/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Bolts.framework" failed: No such file or directory (2)
done

sent 29 bytes  received 20 bytes  98.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/8e85887f-758c-11ee-a904-2a65a1af8551/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9]
Command PhaseScriptExecution failed with a nonzero exit code
shankari commented 6 months ago

This is a known issue with cocoapods https://dev.to/curtlycritchlow/how-to-fix-failed-archive-on-xcode-143-25fh https://github.com/CocoaPods/CocoaPods/pull/11828/files

For now, I have made the change locally. @louisg1337 can you please bump up the version of cocoapods as well? https://github.com/CocoaPods/CocoaPods/pull/11828#issuecomment-1665117910

louisg1337 commented 6 months ago

Sorry for the delay! Here is the PR for the cocoapods bump.

shankari commented 3 months ago

Closing this issue as complete