From daac154d8149613ac1e1f9f297328b64904db706 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 16 Jul 2026 11:25:19 -0400 Subject: [PATCH] Exclude PrivacyInfo.xcprivacy resource on Android Declaring a resource on the SQLite target makes SwiftPM generate a Bundle.module accessor that unconditionally imports Foundation and calls Bundle.main/Bundle(path:), which requires linking all of Foundation (plus FoundationInternationalization and ICU on affected SDKs) even for consumers that otherwise only need FoundationEssentials. PrivacyInfo.xcprivacy only has meaning for the Apple App Store, so this excludes it under a TARGET_OS_ANDROID environment variable, following the same convention swift-android-native uses to detect an Android cross-compile from Package.swift (which always evaluates on the host and has no direct way to see the build destination). No effect on existing consumers since the variable is unset by default. --- Package.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 2395f9f2d..59b0cda28 100644 --- a/Package.swift +++ b/Package.swift @@ -2,6 +2,15 @@ import PackageDescription let applePlatforms: [PackageDescription.Platform] = [.iOS, .macOS, .watchOS, .tvOS, .visionOS] +// Package.swift always compiles for the host, so it can't see the build +// destination directly — an environment variable (matching the convention +// used by swift-android-native's own `TARGET_OS_ANDROID` check) is the only +// way to detect an Android cross-compile here. `PrivacyInfo.xcprivacy` is +// only meaningful for the Apple App Store; declaring it as a resource makes +// SwiftPM generate a `Bundle.module` accessor that requires linking all of +// Foundation on Android, so it's excluded there. +let isAndroid = Context.environment["TARGET_OS_ANDROID"] ?? "0" != "0" + let target: Target = .target( name: "SQLite", dependencies: [ @@ -12,8 +21,8 @@ let target: Target = .target( package: "SQLCipher.swift", condition: .when(platforms: applePlatforms, traits: ["SQLCipher"])) ], - exclude: ["Info.plist"], - resources: [.copy("PrivacyInfo.xcprivacy")], + exclude: isAndroid ? ["Info.plist", "PrivacyInfo.xcprivacy"] : ["Info.plist"], + resources: isAndroid ? [] : [.copy("PrivacyInfo.xcprivacy")], cSettings: [ .define("SQLITE_HAS_CODEC", .when(platforms: applePlatforms, traits: ["SQLCipher"])) ]