Skip to content

Exclude PrivacyInfo.xcprivacy resource on Android#1368

Open
colemancda wants to merge 1 commit into
stephencelis:masterfrom
colemancda:android-exclude-privacy-resource
Open

Exclude PrivacyInfo.xcprivacy resource on Android#1368
colemancda wants to merge 1 commit into
stephencelis:masterfrom
colemancda:android-exclude-privacy-resource

Conversation

@colemancda

Copy link
Copy Markdown
Contributor

Summary

  • Declaring resources: [.copy("PrivacyInfo.xcprivacy")] on the SQLite target makes SwiftPM auto-generate a resource_bundle_accessor.swift file with Bundle.module, which unconditionally imports Foundation and calls Bundle.main/Bundle(path:).
  • On the Android Swift SDK, that pulls in libFoundation.so — and, since it has its own unconditional dependency on libFoundationInternationalization.so + ICU there, all three — for consumers who otherwise only need FoundationEssentials.
  • PrivacyInfo.xcprivacy only has meaning for the Apple App Store, so this excludes it from the target's resources when a TARGET_OS_ANDROID environment variable is set, following the same convention swift-android-native uses to detect an Android cross-compile — Package.swift always evaluates on the host, so it has no direct way to see the actual build destination.
  • No effect on existing consumers: the variable is unset by default, so PrivacyInfo.xcprivacy continues to ship exactly as before everywhere else.

Test plan

  • swift package dump-package — without the env var, resources still includes PrivacyInfo.xcprivacy
  • TARGET_OS_ANDROID=1 swift package dump-packageresources is empty and PrivacyInfo.xcprivacy moves to exclude
  • Cross-compiled a downstream Android app against this branch and confirmed via readelf -d/nm that Bundle.main/Bundle(path:) no longer appear as undefined symbols

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant