Skip to content

Conversation

@vegaro
Copy link
Contributor

@vegaro vegaro commented Aug 28, 2025

We created a PaywallProxyActivity, instead of using the regular fragment we normally use for presenting paywalls in the hybrids. The reason is that we can't use Unity apps use UnityPlayerActivity as the main activity, which is not FragmentActivity. In Flutter we ask devs to implement FragmentActivity in their Activity, but it's not easy to do that in Unity.

For callbacks we use UnitySendMessage, since that's the simplest way without having to rewrite the way we present paywalls to be able to communicate paywall results. It Unity's built-in GameObject messaging system, which I tested and acts as a queue, which is nice since it means the message will come back as soon as PaywallProxyActivity is closed, behaving very similar to onActivityResult. This avoids rewriting existing paywall presentation architecture, which was in progress and we can still do if we want to support real-time paywall notifications.

To hold the Java code, I created a androidlib folder, following the docs https://docs.unity3d.com/Manual/android-library-plugin-create.html. The reason is that it's the only way to include an AndroidManifest.xml, the alternative is building an aar, which wuld require external build process and complicate development workflow.

EDIT: The circular dependency issue is not an issue anymore and has been solved with #649 (comment), but keeping it here for reference

Circular dependency issue

This is how the Gradle dependencies look like:

unityLibrary (main) → depends on → RevenueCatUI.androidlib (our plugin)
RevenueCatUI.androidlib → CANNOT depend on → unityLibrary (circular!)
Screenshot 2025-09-22 at 13 30 34

We need to call Unity functions (see UnityBridge) using reflection. The androidlib is converted into a module, and the unityLibrary module depends on it (implementation project(':RevenueCatUI.androidlib'). That means adding a dependency on unityLibrary in RevenueCatUI.androidlib would create a circular dependency. That's why I build the UnityBridge.

Usage

using RevenueCat.UI;

// Basic paywall presentation
var ui = GetComponent<RevenueCatUI>();
var result = await ui.PresentPaywall();

// Paywall with options
var options = new PaywallOptions {
    OfferingIdentifier = "premium_monthly",
    DisplayCloseButton = true
};
var result = await ui.PresentPaywall(options);

// Conditional paywall
var result = await ui.PresentPaywallIfNeeded("premium_features", options);

Followups

  • Font support
  • PresentedOfferingContext support

@vegaro vegaro added the pr:other Changes to our CI configuration files and scripts label Aug 28, 2025
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

I think the approach makes sense... I just have that question about how the presentPaywallIfNeeded method would look like and whether that could cause any UI glitches by presenting the proxy activity without need though.

@vegaro
Copy link
Contributor Author

vegaro commented Sep 30, 2025

This PR requires RevenueCat/purchases-android#2695

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

Looking pretty good! Just some minor questions and comments

github-merge-queue bot pushed a commit to RevenueCat/purchases-android that referenced this pull request Sep 30, 2025
@vegaro vegaro requested a review from a team as a code owner October 1, 2025 09:12
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

All makes sense to me. Amazing job on this! Only question is whether we want to get the improvements in #682 before shipping this, since it could be a breaking change later otherwise.

@vegaro vegaro merged commit 6845198 into main Oct 3, 2025
7 checks passed
@vegaro vegaro deleted the paywalls-android-poc branch October 3, 2025 07:51
vegaro added a commit that referenced this pull request Oct 3, 2025
vegaro added a commit to RevenueCat/purchases-android that referenced this pull request Oct 15, 2025
vegaro added a commit to RevenueCat/purchases-android that referenced this pull request Oct 15, 2025
vegaro added a commit to RevenueCat/purchases-android that referenced this pull request Oct 15, 2025
vegaro added a commit to RevenueCat/purchases-android that referenced this pull request Oct 15, 2025
vegaro added a commit to RevenueCat/purchases-android that referenced this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:changelog_ignore pr:other Changes to our CI configuration files and scripts pr:RevenueCatUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants