Skip to content

StoreKit2 support for Apple devices#1846

Open
AustinBenoit wants to merge 9 commits intomainfrom
StoreKit2
Open

StoreKit2 support for Apple devices#1846
AustinBenoit wants to merge 9 commits intomainfrom
StoreKit2

Conversation

@AustinBenoit
Copy link
Copy Markdown
Contributor

Description

Provide details of the change, and generalize the change in the PR title above.

StoreKit2 support for Apple devices. Make the LogAppleTransaction a no-op for Android and iOS


Testing

Describe how you've tested these changes. Link any manually triggered Integration tests or CPP binary SDK Packaging Github Action workflows, if applicable.

Added in a new integration test and steps to manually test the transactions.

Performed the manual testing as describe:

image

Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Notes

  • Bug fixes and feature changes require an update to the Release Notes section of release_build_files/readme.md.
  • Read the contribution guidelines CONTRIBUTING.md.
  • Changes to the public API require an internal API review. If you'd like to help us make Firebase APIs better, please propose your change in a feature request so that we can discuss it together.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for logging Apple StoreKit 2 transactions on iOS by adding a new LogAppleTransaction API, including a Swift bridge for native interaction and updated CMake configurations to support Swift compilation. Several issues were identified in the CMake configuration, including a regression for Windows builds, incorrect platform detection logic for tvOS, non-portable header inclusion, and reliance on Xcode-specific variables that break other generators like Ninja.

@AustinBenoit AustinBenoit added the tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). label Apr 9, 2026
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

❌  Integration test FAILED

Requested by @AustinBenoit on commit 66cb596
Last updated: Mon Apr 13 10:23 PDT 2026
View integration test log & download artifacts

Failures Configs
auth
(4 items)[TEST] [FAILURE] [Linux] [1/2 ssl_lib: x86] [1/2 build_type: boringssl]
(1 failed tests)  FirebaseAuthTest.TestSignInWithBadEmailFails
[TEST] [FAILURE] [Windows] [1/2 ssl_lib: x64] [openssl]
(1 failed tests)  FirebaseAuthTest.TestSignInWithBadEmailFails
[TEST] [FAILURE] [Windows] [All 2 ssl_lib] [boringssl]
(1 failed tests)  FirebaseAuthTest.TestSignInWithBadEmailFails
[TEST] [FAILURE] [iOS] [macos] [1/2 ios_device: simulator_target]
(1 failed tests)  FirebaseAuthTest.TestSignInWithBadEmailFails
firestore
(6 items)[TEST] [ERROR] [iOS] [macos] [All 2 ios_device]
[TEST] [ERROR] [tvOS] [macos] [tvos_simulator]
[TEST] [FAILURE] [Android] [1/3 os: windows] [1/4 android_device: emulator_ftl_latest]
(4 failed tests)  FieldsTest.TestFieldsWithSpecialCharsCanBeUsedInOrderBy
  QueryTest.TestKeyOrderIsDescendingForDescendingInequality
  SourceTest.GetCollectionWhileOnlineWithSourceEqualToCache
  TaskTest.IsCompleteShouldReturnTrueForCanceledTask
[TEST] [FLAKINESS] [Android] [1/3 os: macos] [1/4 android_device: emulator_ftl_latest]
(1 failed tests)  AggregateCountTest.TestQueriesCanUseNotEqualFiltersWithDocIds
[TEST] [FLAKINESS] [Android] [1/3 os: macos] [1/4 android_device: emulator_ftl_target]
(1 failed tests)  WriteBatchTest.TestCanWriteTheSameDocumentMultipleTimes
[TEST] [FLAKINESS] [Android] [1/3 os: macos] [2/4 android_device: android_target android_latest]
(1 failed tests)  CRASH/TIMEOUT

Add flaky tests to go/fpl-cpp-flake-tracker

@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Apr 9, 2026
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Apr 9, 2026
@AustinBenoit AustinBenoit added tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). and removed tests: failed This PR's integration tests failed. labels Apr 10, 2026
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: failed This PR's integration tests failed. and removed tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). labels Apr 10, 2026
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Apr 10, 2026
@AustinBenoit AustinBenoit added type: feature request New feature or request tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). and removed type: feature request New feature or request tests: failed This PR's integration tests failed. labels Apr 10, 2026
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: failed This PR's integration tests failed. and removed tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). labels Apr 10, 2026
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Apr 10, 2026
…ocumentation

This commit resolves several known compiler and runtime issues when compiling C++ alongside modern Swift (Concurrency) using Xcode 15+ for deployment on iOS 15/16:

1. `swift_task_alloc` (EXC_BAD_ACCESS): Mixing Swift Concurrency with `@objc` interfaces and C++ pointers on older runtimes causes memory segmentation faults. We introduced an Objective-C++ Block Barrier to keep C pointers on the C++ side (`analytics_ios.mm`) and used a detached `Task` with a pure Swift struct (`AppleTransactionVerifier.swift`) to safely isolate the async `Transaction.all` loop from the bridging boundary.
2. `AsyncIteratorProtocol` (Witness Table Corruption): Using a `for await` loop within an `@objc` class on iOS 15/16 triggers a known Xcode 15+ compiler bug leading to a runtime crash. We bypassed this by extracting the logic into a pure Swift struct and replacing the `for await` loop with manual `while let ... = await iterator.next()` iteration.
3. `__libcpp_verbose_abort`: Xcode 15 requires this symbol for C++ exception handling, but it is missing from the iOS 15/16 system `libc++`. We disabled verbose abort globally via `CMakeLists.txt` and provided a weak fallback implementation in `app_framework.cc` for integration tests to prevent a `dyld` launch crash.
4. `libswift_Concurrency.dylib`: The Swift compiler sometimes fails to weak-link the Concurrency backward compatibility library in Objective-C++ projects. We now natively inject `-Wl,-weak-lswift_Concurrency` into all integration test Xcode projects during `setup_integration_tests.py`.

Internal dialog comments have been cleaned up and replaced with professional explanations suitable for open-source maintainers.
Documentation in `release_build_files/readme.md` has been updated to provide clear instructions for manual C++ integrators to apply these linker/compiler flags if they experience similar crashes.
@AustinBenoit
Copy link
Copy Markdown
Contributor Author

/gemini review

@AustinBenoit AustinBenoit added tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). and removed tests: failed This PR's integration tests failed. labels Apr 13, 2026
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: full Trigger a FULL set of integration tests (uses expanded test matrix). labels Apr 13, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the LogAppleTransaction API to Firebase Analytics, enabling the logging of StoreKit 2 transactions on iOS and tvOS. The implementation includes a Swift-based verification layer using AppleTransactionWorker and bridges it to the C++ SDK. Additionally, the PR incorporates critical workarounds for Xcode 15+ compatibility on older iOS versions (15 and 16), specifically addressing potential crashes related to Swift Concurrency and __libcpp_verbose_abort. Build system updates across multiple modules ensure proper Swift/C++ interop and framework linking. Review feedback suggests addressing a potential memory leak in the iOS asynchronous completion handling and improving the portability of the CMake configuration by removing hardcoded framework paths.

return Future<void>(api, future_handle.get());
}

SafeFutureHandle<void>* handle_ptr = new SafeFutureHandle<void>(future_handle);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SafeFutureHandle<void> is allocated on the heap using new, but there is a risk of a memory leak if the verifyWithTransactionId completion block is never executed. While the current Swift implementation appears to always call the completion handler, it is safer to use a mechanism that ensures cleanup even if the asynchronous task fails to complete or if the app state changes unexpectedly.

Comment on lines +194 to +195
set(analytics_framework_dir "${pods_dir}/FirebaseAnalytics/Frameworks/FirebaseAnalytics.xcframework/${analytics_slice}")
set(measurement_framework_dir "${pods_dir}/GoogleAppMeasurement/Frameworks/GoogleAppMeasurement.xcframework/${analytics_slice}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The paths for FirebaseAnalytics.xcframework and GoogleAppMeasurement.xcframework are hardcoded based on a specific CocoaPods directory structure. This may cause build failures if the environment uses a different version of the Firebase Apple SDK or a different dependency management setup. Consider using CMake variables or a more flexible discovery mechanism to locate these frameworks.

@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Apr 13, 2026
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Apr 13, 2026
@AustinBenoit AustinBenoit requested a review from a-maurice April 13, 2026 18:02
@AustinBenoit AustinBenoit marked this pull request as ready for review April 13, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests: failed This PR's integration tests failed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant