Skip to content

Instantly share code, notes, and snippets.

@jpudysz
Last active December 30, 2025 01:07
Show Gist options
  • Select an option

  • Save jpudysz/c04217fe3f9a584471bcb988407d2ee3 to your computer and use it in GitHub Desktop.

Select an option

Save jpudysz/c04217fe3f9a584471bcb988407d2ee3 to your computer and use it in GitHub Desktop.
Expo plugin to add SPM dependency to main targer
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
{
"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"
}]
]
}
}
@bhyoo99
Copy link

bhyoo99 commented Jul 11, 2025

@birkir

module.exports = addSPMDependenciesToMainTarget

@meet-rizwan
Copy link

meet-rizwan commented Nov 3, 2025

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

@KrysKruk
Copy link

KrysKruk commented Dec 8, 2025

In case you see an error like "PluginError: Unable to resolve a valid config plugin for ...":

  1. Move the addSPMDependenciesToMainTarget file into addSPMDependenciesToMainTarget/app.plugin.js
  2. Create package.json in the new directory with "main" path pointing to the app.plugin.js

Also it should be module.exports (without s in modules).

@lyccccc1piano
Copy link

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"
        }
      ]
    ]

check here  请点击此处

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