adaptyteam / AdaptySDK-Flutter

SDK for growing mobile in-app purchases
https://docs.adapty.io/docs/quickstart
MIT License
96 stars 18 forks source link

AdaptyError (code null) . Error thrown null. Android. Release. #30

Closed radomir9720 closed 2 years ago

radomir9720 commented 2 years ago

Hi. I have have set up Adapty SDK and tested in debug with sandbox for android and ios. Everything worked well, as expected, but when i built a release, i started getting exceptions AdaptyError (code null) . Error thrown null.. In Profile mode everything works well.

The exception is thrown after calling Adapty.identify() and Adapty.getPaywalls().

Tested on Huawei P20 lite android 9, and Samsung Galaxy S9 android 9.

Trace ``` Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: AdaptyError (code null) . Error thrown null. at Adapty._invokeMethodHandlingErrors(Adapty.java:242) at Adapty.getPaywalls(Adapty.java:64) at PurchaseBloc._purchase.(_purchase.java:79) at PurchaseBloc._tryCatchWrapper(PurchaseBloc.java:39) at PurchaseBloc._purchase(PurchaseBloc.java:76) at Bloc.on..handleEvent(.java:456) ```
How i activate adapty ```dart void main() { runZonedGuarded(_run, CrashlyticsHelper.recordError); } Future _run() async { WidgetsFlutterBinding.ensureInitialized(); // FB await Firebase.initializeApp(); final analytics = FirebaseAnalytics(); await analytics.setAnalyticsCollectionEnabled(!kDebugMode); await analytics.logAppOpen(); await DeviceInfoHelper.initialize(); // error observers Bloc.observer = FirebaseBlocObserver(); FlutterError.onError = CrashlyticsHelper.recordFlutterError; CrashlyticsHelper.log(DeviceInfoHelper.instance.infoMap.toString()); // Adapty Adapty.activate(); // final installId = DeviceInfoHelper.instance.deviceId; // await Adapty.identify(installId); await Adapty.setLogLevel(AdaptyLogLevel.verbose); runApp(); } ```
vladd-g commented 2 years ago

@radomir9720 hi, does it happen on the latest sdk version?

Actually I think it may be an obfuscation issue, since the sdk source code is not split to debug/release, and, as you said, everything worked well in debug

radomir9720 commented 2 years ago

Yes, it happens on latest 1.0.6 version.

vladd-g commented 2 years ago

Is it reproduced stably in release? Do you use obfuscation?

radomir9720 commented 2 years ago

Yes, stably. And yes, i use obfuscation. In my app build.gradle in buildTypes i have set previously minifyEnabled and shrinkResources both to true. Now i tried to comment these lines, built a release apk, and still no positive result. Exactly the same error.

vladd-g commented 2 years ago

That's strange, we'll try to reproduce the problem.

Btw, do you have the following line in the proguard config? -keep class com.adapty.** { *; }

radomir9720 commented 2 years ago

I don't have any proguard config at all, but i configured one, and the error persists.

shok96 commented 2 years ago

I do not use obfuscation and it also does not work for me in the release, in the debug mode everything is fine.

the error occurs when calling

final GetPaywallsResult getPaywallsResult = await Adapty
                    .getPaywalls(forceUpdate: false);

[+6696 ms] E/flutter (17291): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: AdaptyError (code null) [ ] E/flutter (17291): #0 Adapty._invokeMethodHandlingErrors (package:adapty_flutter/adapty_flutter.dart:242) [ ] E/flutter (17291): [ ] E/flutter (17291): #1 Adapty.getPaywalls (package:adapty_flutter/adapty_flutter.dart:64) [ ] E/flutter (17291): [ ] E/flutter (17291): #2 SubscribePan.build. (package:imagepicker/widgets/subscribe_pan.dart:33) [ ] E/flutter (17291): [ ] E/flutter (17291):

Adapty.getPaywalls (package:adapty_flutter/adapty_flutter.dart:64)

  static Future<GetPaywallsResult> getPaywalls({bool forceUpdate = false}) async {
    final result = (await _invokeMethodHandlingErrors<String>(Method.getPaywalls, {
      Argument.forceUpdate: forceUpdate,
    })) as String;
    return GetPaywallsResult.fromMap(json.decode(result));
  }

Adapty._invokeMethodHandlingErrors (package:adapty_flutter/adapty_flutter.dart:242)

  static Future<T?> _invokeMethodHandlingErrors<T>(String method, [dynamic arguments]) async {
    try {
      return await _channel.invokeMethod<T>(method, arguments);
    } on PlatformException catch (e) {
      throw e.details != null ? AdaptyError.fromMap(json.decode(e.details)) : e;
    }
  }
shok96 commented 2 years ago

I found the problem nowhere is it written about this, I just had to compare the example code with my project in new versions of flutter in the file.gradle file the following construction is written

subprojects {
     project.buildDir = "$ {rootProject.buildDir} / $ {project.name}"
     project.evaluationDependsOn (': app')
}

and in the example it is written like this

subprojects {
     project.buildDir = "$ {rootProject.buildDir} / $ {project.name}"
}
subprojects {
     project.evaluationDependsOn (': app')
}

after replacing the site as in the example, the subscriptions earned in the release.

vladd-g commented 2 years ago

@shok96 cool, thank you, closing the issue