[Bug]: cap sync drops the minor version of IPHONEOS_DEPLOYMENT_TARGET in CapApp-SPM/Package.swift, so plugins that require e.g. iOS 15.6 or 16.4 fail to resolve

Abierto Apto para principiantes
#8,759 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ios, swift, typescript

Línea de trabajo

Lee getMajoriOSVersion en cli/src/ios/common.ts y generatePackageText en cli/src/util/spm.ts; el issue enlaza ambos puntos de entrada e incluye una reproducción. Ejecuta la reproducción con un destino de despliegue como 16.4 y, después, inspecciona el archivo ios/App/CapApp-SPM/Package.swift generado. El trabajo estará terminado cuando la declaración de plataforma de iOS conserve el destino de despliegue completo de la app y la resolución de paquetes demostrada se complete correctamente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

triage
Capacitor Version
💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 9.0.0
  @capacitor/core: 9.0.0
  @capacitor/android: 9.0.0
  @capacitor/ios: 9.0.0

Installed Dependencies:

  @capacitor/android: not installed
  @capacitor/cli: 9.0.0
  @capacitor/core: 9.0.0
  @capacitor/ios: 9.0.0

[success] iOS looking great! 👌

Our app is on Capacitor 8.6.0, where we hit this. The doctor output above is from the reproduction on 9.0.0 (current latest), to show it is still present. Also reproduced with @capacitor/cli 8.6.0 and 8.6.3.

Other API Details
npm 11.20.0, node v26.13.0, Xcode 27.1 (27A9275), SPM
Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

cap sync ios writes only the major part of the app's deployment target into ios/App/CapApp-SPM/Package.swift.

With IPHONEOS_DEPLOYMENT_TARGET = 16.4 the generated file contains:

platforms: [.iOS(.v16)],

.v16 means 16.0. If any plugin (or an SDK a plugin depends on) declares a minimum between x.1 and x.9, package resolution fails, even though the app's real deployment target satisfies it:

error: The package product 'MinPlugin-product' requires minimum platform version 16.4 for the iOS platform, but this target supports 16.0 (in target 'CapApp-SPM' from project 'CapApp-SPM')

Same result on Capacitor 8.6.0 and 8.6.3 with IPHONEOS_DEPLOYMENT_TARGET = 15.6: the file gets .iOS(.v15) and the error reads "requires minimum platform version 15.6 ... but this target supports 15.0".

The plugin cannot work around it by lowering its own platforms:. When the minimum comes from a dependency (for example a vendor SDK shipped as a binary Swift package that declares .iOS("15.6")), the same error just moves one level down, to the plugin target.

Editing the generated line by hand to .iOS("16.4") makes the project build, but the file is regenerated on every sync.

The same app builds with CocoaPods, because the Podfile carries the full version (platform :ios, '15.6').

getMajoriOSVersion reads two characters after the first IPHONEOS_DEPLOYMENT_TARGET = in project.pbxproj:

https://github.com/ionic-team/capacitor/blob/7310cb08a098cb4692488067c15a47d1cc107b8c/cli/src/ios/common.ts#L125-L133

and generatePackageText writes that value with the symbolic form:

https://github.com/ionic-team/capacitor/blob/7310cb08a098cb4692488067c15a47d1cc107b8c/cli/src/util/spm.ts#L104

https://github.com/ionic-team/capacitor/blob/7310cb08a098cb4692488067c15a47d1cc107b8c/cli/src/util/spm.ts#L119

Expected Behavior

CapApp-SPM/Package.swift declares the same deployment target as the app. When the target has a minor part, the string form is needed, since .vXX only exists for major versions:

platforms: [.iOS("16.4")],

This is not a request to change Capacitor's own minimum. It is only about the generated package matching the value the app already has in Xcode.

Project Reproduction

https://github.com/mgarrido-fiwind/capacitor-spm-minor-version-repro

Additional Information

Steps below (no repo needed). Pass 8.6.0 15.6 or 8.6.3 15.6 as arguments to reproduce on Capacitor 8.

CAP="${1:-9.0.0}"       # also reproduces with 8.6.3
TARGET="${2:-16.4}"     # use 15.6 with Capacitor 8
SWIFT_PM="${CAP%%.*}.0.0"

mkdir repro && cd repro && mkdir www && touch www/index.html
echo '{"appId":"com.example.repro","appName":"repro","webDir":"www"}' > capacitor.config.json
npm init -y > /dev/null
npm i @capacitor/core@$CAP @capacitor/ios@$CAP && npm i -D @capacitor/cli@$CAP

# A local plugin whose Swift package requires the same minor version as the app.
mkdir -p min-plugin/ios/Sources/MinPlugin
echo '{ "name": "min-plugin", "version": "1.0.0", "capacitor": { "ios": { "src": "ios" } } }' > min-plugin/package.json
cat > min-plugin/Package.swift <<EOF
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "MinPlugin",
    platforms: [.iOS("$TARGET")],
    products: [.library(name: "MinPlugin", targets: ["MinPlugin"])],
    dependencies: [
        .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "$SWIFT_PM")
    ],
    targets: [
        .target(
            name: "MinPlugin",
            dependencies: [.product(name: "Capacitor", package: "capacitor-swift-pm")],
            path: "ios/Sources/MinPlugin")
    ]
)
EOF
cat > min-plugin/ios/Sources/MinPlugin/MinPlugin.swift <<'EOF'
import Capacitor

@objc(MinPlugin)
public class MinPlugin: CAPPlugin, CAPBridgedPlugin {
    public let identifier = "MinPlugin"
    public let jsName = "Min"
    public let pluginMethods: [CAPPluginMethod] = []
}
EOF
npm i ./min-plugin

npx cap add ios --packagemanager SPM
sed -i '' "s/IPHONEOS_DEPLOYMENT_TARGET = [0-9.]*;/IPHONEOS_DEPLOYMENT_TARGET = $TARGET;/g" ios/App/App.xcodeproj/project.pbxproj
npx cap sync ios

grep -m1 IPHONEOS_DEPLOYMENT_TARGET ios/App/App.xcodeproj/project.pbxproj
grep platforms ios/App/CapApp-SPM/Package.swift
xcodebuild -project ios/App/App.xcodeproj -scheme App -destination 'generic/platform=iOS' CODE_SIGNING_ALLOWED=NO build 2>&1 | grep -E "error:|BUILD"

Output with the defaults (Capacitor 9.0.0):

IPHONEOS_DEPLOYMENT_TARGET = 16.4;
    platforms: [.iOS(.v16)],
error: The package product 'MinPlugin-product' requires minimum platform version 16.4 for the iOS platform, but this target supports 16.0 (in target 'CapApp-SPM' from project 'CapApp-SPM')
** BUILD FAILED **

Output with 8.6.0 15.6 and with 8.6.3 15.6:

IPHONEOS_DEPLOYMENT_TARGET = 15.6;
    platforms: [.iOS(.v15)],
error: The package product 'MinPlugin-product' requires minimum platform version 15.6 for the iOS platform, but this target supports 15.0 (in target 'CapApp-SPM' from project 'CapApp-SPM')
** BUILD FAILED **
Lenguaje dominante
TypeScript
Estrellas
17.1k
Forks
1.3k
Merge medio
1 d 22 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ionic-team/capacitor

Todos los issues de ionic-team/capacitor

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.