Last active
December 30, 2025 01:07
-
-
Save jpudysz/c04217fe3f9a584471bcb988407d2ee3 to your computer and use it in GitHub Desktop.
Expo plugin to add SPM dependency to main targer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { withXcodeProject } = require('@expo/config-plugins') | |
| const addSPMDependenciesToMainTarget = (config, options) => withXcodeProject(config, config => { | |
| const { version, repositoryUrl, repoName, productName } = options | |
| const xcodeProject = config.modResults | |
| // update XCRemoteSwiftPackageReference | |
| const spmReferences = xcodeProject.hash.project.objects['XCRemoteSwiftPackageReference'] | |
| if (!spmReferences) { | |
| xcodeProject.hash.project.objects['XCRemoteSwiftPackageReference'] = {} | |
| } | |
| const packageReferenceUUID = xcodeProject.generateUuid() | |
| xcodeProject.hash.project.objects['XCRemoteSwiftPackageReference'][`${packageReferenceUUID} /* XCRemoteSwiftPackageReference "${repoName}" */`] = { | |
| isa: 'XCRemoteSwiftPackageReference', | |
| repositoryURL: repositoryUrl, | |
| requirement: { | |
| kind: 'upToNextMajorVersion', | |
| minimumVersion: version | |
| } | |
| } | |
| // update XCSwiftPackageProductDependency | |
| const spmProducts = xcodeProject.hash.project.objects['XCSwiftPackageProductDependency'] | |
| if (!spmProducts) { | |
| xcodeProject.hash.project.objects['XCSwiftPackageProductDependency'] = {} | |
| } | |
| const packageUUID = xcodeProject.generateUuid() | |
| xcodeProject.hash.project.objects['XCSwiftPackageProductDependency'][`${packageUUID} /* ${productName} */`] = { | |
| isa: 'XCSwiftPackageProductDependency', | |
| // from step before | |
| package: `${packageReferenceUUID} /* XCRemoteSwiftPackageReference "${repoName}" */`, | |
| productName: productName | |
| } | |
| // update PBXProject | |
| const projectId = Object.keys(xcodeProject.hash.project.objects['PBXProject']).at(0) | |
| if (!xcodeProject.hash.project.objects['PBXProject'][projectId]['packageReferences']) { | |
| xcodeProject.hash.project.objects['PBXProject'][projectId]['packageReferences'] = [] | |
| } | |
| xcodeProject.hash.project.objects['PBXProject'][projectId]['packageReferences'] = [ | |
| ...xcodeProject.hash.project.objects['PBXProject'][projectId]['packageReferences'], | |
| `${packageReferenceUUID} /* XCRemoteSwiftPackageReference "${repoName}" */`, | |
| ] | |
| // update PBXBuildFile | |
| const frameworkUUID = xcodeProject.generateUuid() | |
| xcodeProject.hash.project.objects['PBXBuildFile'][`${frameworkUUID}_comment`] = `${productName} in Frameworks` | |
| xcodeProject.hash.project.objects['PBXBuildFile'][frameworkUUID] = { | |
| isa: 'PBXBuildFile', | |
| productRef: packageUUID, | |
| productRef_comment: productName | |
| } | |
| // update PBXFrameworksBuildPhase | |
| const buildPhaseId = Object.keys(xcodeProject.hash.project.objects['PBXFrameworksBuildPhase']).at(0) | |
| if (!xcodeProject.hash.project.objects['PBXFrameworksBuildPhase'][buildPhaseId]['files']) { | |
| xcodeProject.hash.project.objects['PBXFrameworksBuildPhase'][buildPhaseId]['files'] = [] | |
| } | |
| xcodeProject.hash.project.objects['PBXFrameworksBuildPhase'][buildPhaseId]['files'] = [ | |
| ...xcodeProject.hash.project.objects['PBXFrameworksBuildPhase'][buildPhaseId]['files'], | |
| `${frameworkUUID} /* ${productName} in Frameworks */`, | |
| ] | |
| return config | |
| }) | |
| modules.exports = addSPMDependenciesToMainTarget |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "expo": { | |
| "plugins": [ | |
| ["./plugins/addSPMDependenciesToMainTarget.js", { | |
| "version": "3.6.0", | |
| "repositoryUrl": "https://github.com/Adyen/adyen-pos-mobile-ios-test", | |
| "repoName": "adyen-pos-mobile-ios-test", | |
| "productName": "AdyenPOSTEST" | |
| }] | |
| ] | |
| } | |
| } |
In the Expo module API, when I add this code and prebuild, it works, but when I run yarn ios or build it from Xcode, it throws an error
No such module 'CXoneChatSDK'
"plugins": [
"expo-router",
[
"../plugins/addSPMDependenciesToMainTarget.js",
{
"version": "3.0.1",
"repositoryUrl": "https://github.com/nice-devone/nice-cxone-mobile-sdk-ios",
"repoName": "nice-cxone-mobile-sdk-ios",
"productName": "CXoneChatSDK"
}
]
]check here
In case you see an error like "PluginError: Unable to resolve a valid config plugin for ...":
- Move the
addSPMDependenciesToMainTargetfile intoaddSPMDependenciesToMainTarget/app.plugin.js - Create
package.jsonin the new directory with "main" path pointing to theapp.plugin.js
Also it should be module.exports (without s in modules).
In the Expo module API, when I add this code and prebuild, it works, but when I run yarn ios or build it from Xcode, it throws an error在 Expo 模块 API 中,当我添加这段代码并进行预构建时,它可以正常工作,但是当我运行
yarn ios或从 Xcode 构建时,它会抛出错误。No such module 'CXoneChatSDK'"plugins": [ "expo-router", [ "../plugins/addSPMDependenciesToMainTarget.js", { "version": "3.0.1", "repositoryUrl": "https://github.com/nice-devone/nice-cxone-mobile-sdk-ios", "repoName": "nice-cxone-mobile-sdk-ios", "productName": "CXoneChatSDK" } ] ]
I also encountered this problem. Is there a solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@birkir