RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
609 stars 170 forks source link

This declaration needs opt-in #1103

Closed arabnology closed 4 months ago

arabnology commented 5 months ago

‼️ Required data ‼️

Do not remove any of the steps from the template below. If a step is not applicable to your issue, please leave that step empty.

There are a lot of things that can contribute to things not working. Having a very basic understanding of your environment will help us understand your issue faster!

Environment

• No issues found!

FAILURE: Build failed with an exception.

BUILD FAILED in 49s Error: Gradle task assembleDebug failed with exit code 1

**Other information** (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

## Describe the bug ##
Here is my code:

static Future initPurchases({ final VoidCallback? onStart, final VoidCallback? onSuccess, final void Function(String error)? onError, final VoidCallback? onComplete, }) async { try { onStart?.call(); if (_purchasesConfiguration != null) { onSuccess?.call(); return true; } if (Platform.isAndroid) { _purchasesConfiguration = PurchasesConfiguration(_googleApiKey); } else if (Platform.isIOS) { _purchasesConfiguration = PurchasesConfiguration(_appleApiKey); } else { _purchasesConfiguration = null; } if (_purchasesConfiguration != null) { await Purchases.configure(_purchasesConfiguration!).timeout(const Duration(seconds: 16)); onSuccess?.call(); return true; } else { onError?.call(LanguageManager.translation.error_try_again); } } on TimeoutException { onError?.call(LanguageManager.translation.connectiontimeout); } catch () { onError?.call(LanguageManager.translation.error_try_again); } finally { onComplete?.call(); } return false; }

static Future startPurchasing({ final VoidCallback? onStart, final VoidCallback? onSuccess, final void Function(String error)? onError, final VoidCallback? onComplete, }) async { try { onStart?.call(); final PaywallResult paywallResult = await RevenueCatUI.presentPaywallIfNeeded( "iconvo_premium_enti1", displayCloseButton: true, ); if (paywallResult == PaywallResult.purchased || paywallResult == PaywallResult.restored) { onSuccess?.call(); return true; } else { onError?.call(LanguageManager.translation.error_try_again); } } on TimeoutException { onError?.call(LanguageManager.translation.connectiontimeout); } catch () { onError?.call(LanguageManager.translation.error_try_again); } finally { onComplete?.call(); } return false; }

Starting the payment:

void _startPurchasing() { if (ConnectivityManager.connectedToInternet.value) { PurchaseManager.initPurchases( onStart: () { setState(() { _actionActive = true; }); }, onSuccess: () { PurchaseManager.startPurchasing( onSuccess: () { print("onSuccess"); }, onError: (error) { DialogsManager.showAlertDialog( title: LanguageManager.translation.error, content: error, actions: (context) => [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text( LanguageManager.translation.ok, style: ThemeManager.theme.textTheme.labelLarge, ), ), ], ); }, onComplete: () { setState(() { _actionActive = false; }); }, ); }, onError: (error) { setState(() { _actionActive = false; }); DialogsManager.showAlertDialog( title: LanguageManager.translation.error, content: error, actions: (context) => [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text( LanguageManager.translation.ok, style: ThemeManager.theme.textTheme.labelLarge, ), ), ], ); }, ); } else { DialogsManager.showAlertDialog( title: LanguageManager.translation.error, content: LanguageManager.translation.no_internet_connection, actions: (context) => [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text( LanguageManager.translation.ok, style: ThemeManager.theme.textTheme.labelLarge, ), ), ], ); } }


## Additional context ##
This problem happened only on Android.
RCGitBot commented 5 months ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

arabnology commented 5 months ago

Any updates on this ?

hussain-mustafa990 commented 5 months ago

Any updates?

arabnology commented 5 months ago

Any updates?

Do you have the same problem ?

hussain-mustafa990 commented 5 months ago

Any updates?

Do you have the same problem ?

Yes I do. I was able to fix the issue with downgrading the dependencies to

purchases_flutter: 6.24.0
purchases_ui_flutter: 6.24.0

I also noticed that if you change the minSdk version to 24, then the issue does not appear for the latest release. However, my project requires minSdk version 26 for android and due to that the latest release cause the original posted issue. Hence, my workaround was to downgrade the package versions. Hope this helps. :)

rglanz-rc commented 5 months ago

Hi @arabnology, could you confirm which minSdkVersion you are setting? I'll use that to try to reproduce this issue.

arabnology commented 5 months ago

Hi @arabnology, could you confirm which minSdkVersion you are setting? I'll use that to try to reproduce this issue.

Hi, this is my Android app gradle:

android {
    compileSdk = 35
    ndkVersion = "27.0.11902837"
    namespace = "..."

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId = "..."
        minSdk = 24
        targetSdk = 35
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias = keystoreProperties['keyAlias']
            keyPassword = keystoreProperties['keyPassword']
            storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword = keystoreProperties['storePassword']
        }
    }

    buildFeatures {
        buildConfig true
    }

    buildTypes {
        release {
            signingConfig = signingConfigs.release
        }
    }
}
arabnology commented 5 months ago

Hi @arabnology, could you confirm which minSdkVersion you are setting? I'll use that to try to reproduce this issue.

Can you guys please fix this issue ASAP, as we are waiting for the fixes to release the app?

arabnology commented 4 months ago

Hellooo ?! you guys will fix this or not ?

arabnology commented 4 months ago

Any updates ?

arabnology commented 4 months ago

Any updates?

Do you have the same problem ?

Yes I do. I was able to fix the issue with downgrading the dependencies to

purchases_flutter: 6.24.0
purchases_ui_flutter: 6.24.0

I also noticed that if you change the minSdk version to 24, then the issue does not appear for the latest release. However, my project requires minSdk version 26 for android and due to that the latest release cause the original posted issue. Hence, my workaround was to downgrade the package versions. Hope this helps. :)

Downgrading the version to 6.24.0 is a bad idea because this version has a lot of issues on Android, especially if the store is not available and the user must sign in to the store. I have tested it out.

Thank you :(

arabnology commented 4 months ago

Still not working in version purchases_ui_flutter 6.30.0

hyped0001 commented 4 months ago

Bump

arabnology commented 4 months ago

Bump

Go to flutter plugins, open purchases_ui_flutter Open android folder Then go the class PurchasesUiFlutterPlugin.ktx in src.main

Add "@com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI" (Remove "" when adding) in top of the class name, it will work.

But i dont know if it has any bad side or effect

Darryl1702 commented 4 months ago

Go to flutter plugins, open purchases_ui_flutter

Hi, how will I go to flutter plugins?

arabnology commented 4 months ago

Go to flutter plugins, open purchases_ui_flutter

Hi, how will I go to flutter plugins?

flu_plg_src

On Android Studio, it's on the left side at the bottom, check the screenshot.

I would recommend that you create your own paywall, as I have done, for two reasons:

First, there are a lot of issues, error messages are not customizable and are very limited.

Second, they will take a lot of time to fix the issues.

I have created my own paywall, and it looks similar to theirs but is more customizable, i handled all errors and it is crazy fast.

Darryl1702 commented 4 months ago

Do you know how to implement purchasing trials in android? That is the reason why I started using purchases UI. I already know how to purchase trials in ios.

arabnology commented 4 months ago

Do you know how to implement purchasing trials in android? That is the reason why I started using purchases UI. I already know how to purchase trials in ios.

Yes, simply ask ChatGPT this question and it will tell you how to do that exactly: "Do you know how to implement purchasing trials in android?"

vegaro commented 4 months ago

We are very sorry we missed replying to this issue. I just merged #1112 which will fix it in the next release.