TimmyRB / snapkit

SnapKit is a Flutter plugin that allows you to integrate Snapchat's own SDKs into your Flutter projects!
https://pub.dev/packages/snapkit
MIT License
30 stars 16 forks source link

Platform Exception Error when running app in release mode #34

Open codesbyatif opened 2 years ago

codesbyatif commented 2 years ago

Steps to Reproduce

  1. When the login button is pressed in release mode the platform error occurs

Expected results: Successful Login

Actual results: E/flutter (27362): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(UnknownGetUserError, Unknown Error, 400, null) E/flutter (27362): #0 Snapkit.currentUser (package:snapkit/snapkit.dart:138) E/flutter (27362): E/flutter (27362): #1 Snapkit.login (package:snapkit/snapkit.dart:57) E/flutter (27362): E/flutter (27362):**

Logs ``` info • This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: HomeScreen.snapchatUser • lib/Screens/HomeScreen.dart:21:7 • must_be_immutable info • 'overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/HomeScreen.dart:501:59 • deprecated_member_use info • 'Overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/HomeScreen.dart:502:63 • deprecated_member_use info • Cancel instances of dart.async.StreamSubscription • lib/Screens/Mainscreen.dart:22:36 • cancel_subscriptions info • Unused import: 'package:path_provider/path_provider.dart' • lib/Screens/NewSnapScreen.dart:11:8 • unused_import info • This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: NewSnapScreen.snapchatUser • lib/Screens/NewSnapScreen.dart:17:7 • must_be_immutable info • 'overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/NewSnapScreen.dart:227:13 • deprecated_member_use info • 'Overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/NewSnapScreen.dart:227:23 • deprecated_member_use info • 'overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/NewSnapScreen.dart:419:31 • deprecated_member_use info • 'Overflow' is deprecated and shouldn't be used. Use clipBehavior instead. See the migration guide in flutter.dev/go/clip-behavior. This feature was deprecated after v1.22.0-12.0.pre. • lib/Screens/NewSnapScreen.dart:419:41 • deprecated_member_use ``` ``` [✓] Flutter (Channel stable, 2.2.3-0.0.pre.2, on Mac OS X 10.15.7 19H1323 darwin-x64, locale en-PK) • Flutter version 2.2.3-0.0.pre.2 at /Users/Flash/Developer/flutter • Framework revision a794a412e1 (6 months ago), 2021-06-12 17:13:00 +0500 • Engine revision 91c9fc8fe0 • Dart version 2.13.3 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/Flash/Library/Android/sdk • Platform android-31, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.62.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (2 available) • Nokia 6 1 (mobile) • PL2GAMU841604032 • android-arm64 • Android 10 (API 29) • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.55 • No issues found! ```
TimmyRB commented 2 years ago

Are you using the example app or your own app? Does the same error occur when using the Staging Client ID? What platform & device are you running it on that causes this? Please include your AndroidManifest.xml if this is happening on Android or your Info.plist if it happens on iOS

codesbyatif commented 2 years ago

it's working completely fine on debug and profile mode but giving error in release mode. same error with my own project as well as example with both staging and production Client ID Running it on Android 10 My Android.manifest: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.maahey.unknown">

<application android:label="Unknown" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher"> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/logo" /> <meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="**"/>

    <meta-data
        android:name="com.snapchat.kit.sdk.redirectUrl"
        android:value="unknown://snapchat/oauth2" />

    <meta-data
        android:name="com.snapchat.kit.sdk.scopes"
        android:resource="@array/snap_connect_scopes" />

    <activity
        android:name="com.snapchat.kit.sdk.SnapKitActivity"
        android:launchMode="singleTask">

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- Change this to match your redirect URL -->
            <data
                android:scheme="unknown"
                android:host="snapchat"
                android:path="/oauth2" />
        </intent-filter>
    </activity>
    <provider
       android:name="androidx.core.content.FileProvider"
       android:authorities="${applicationId}.fileprovider"
       android:exported="false"
       android:grantUriPermissions="true">
       <meta-data
           android:name="android.support.FILE_PROVIDER_PATHS"
           android:resource="@xml/file_paths" />
   </provider>
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />

        <meta-data
          android:name="io.flutter.embedding.android.SplashScreenDrawable"
          android:resource="@drawable/launch_background"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
<queries>
    <package android:name="com.snapchat.android"/>
</queries>

TimmyRB commented 2 years ago

It looks like you're missing quite a few things in your AndroidManifest.xml, make sure you followed the instructions on the Wiki

codesbyatif commented 2 years ago

Example project is giving the same error and i have gone through android.manifest multiple times, please if you can let me know what i am missing there.

TimmyRB commented 2 years ago

I was able to reproduce this error, as far as I can tell the error occurs because you're using the Staging key from the Snapchat Developer Portal in a release build instead of the Production key which requires that your app is approved by Snapchat before it can be used, however I will do some more testing soon to make sure. If you're able to get your app approved by Snapchat, try switching to the Production key and let me know if your release build starts working once making the switch!

codesbyatif commented 2 years ago

The app is approved from snapkit developer portal and I am using the production client id here with staging and production client id and it's working fine in debug and profile mode. Screenshot 2021-12-09 at 11 52 45 AM I am using this production key in my android.manifest file

TimmyRB commented 2 years ago

Where are you using the Production Key in your AndroidManifest.xml, the line to include it isn't in the code you provided as the top part of your AndroidManifest.xml is missing?

codesbyatif commented 2 years ago

My bad, it is there but I forgot to copy that here is my androidmanifest.xml

<application
    android:label="Unknown"
    android:usesCleartextTraffic="true"
    android:icon="@mipmap/ic_launcher">
    <meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/logo" />
    <meta-data
        android:name="com.snapchat.kit.sdk.clientId"
        android:value="***************"/>
<meta-data
    android:name="com.snapchat.kit.sdk.redirectUrl"
    android:value="unknown://snapchat/oauth2" />

<meta-data
    android:name="com.snapchat.kit.sdk.scopes"
    android:resource="@array/snap_connect_scopes" />

<activity
    android:name="com.snapchat.kit.sdk.SnapKitActivity"
    android:launchMode="singleTask">

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- Change this to match your redirect URL -->
        <data
            android:scheme="unknown"
            android:host="snapchat"
            android:path="/oauth2" />
    </intent-filter>
</activity>
<provider
   android:name="androidx.core.content.FileProvider"
   android:authorities="${applicationId}.fileprovider"
   android:exported="false"
   android:grantUriPermissions="true">
   <meta-data
       android:name="android.support.FILE_PROVIDER_PATHS"
       android:resource="@xml/file_paths" />

<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

    <meta-data
      android:name="io.flutter.embedding.android.NormalTheme"
      android:resource="@style/NormalTheme"
      />

    <meta-data
      android:name="io.flutter.embedding.android.SplashScreenDrawable"
      android:resource="@drawable/launch_background"
      />
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
<!-- Don't delete the meta-data below.
     This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
    android:name="flutterEmbedding"
    android:value="2" />

dammalani commented 2 years ago

Did anyone find the solution for this? I have the same issue, working fine on debug mode, and not working on release apk. I am using production client Id.

zeshanmusaw commented 2 years ago

Did anyone find the solution for this? I have the same issue, working fine on debug mode, and not working on release apk. I am using production client Id. Please any one have solution for this , Thanks

markszente commented 2 years ago

Hey @atif2148, did you manage to solve this? Also, how long did it take to get your Snap Kit app approved? Thanks.

markszente commented 2 years ago

Hello @atif2148 @dammalani @zeshanmusaw, as of Snap Kit v1.13.0, SnapLogin#fetchUserData(), which this plugin uses, has been deprecated, which may or may not be the cause of this issue. There is a new fetchUserData() in the SnapLoginApi interface. I've forked this repo, upgraded to v1.13.1 and re-implemented the getUser logic. For now, I have no way of checking whether this works in release mode, because Snapchat has yet to approve my app...

Could you tell me how much time did the the review take in your cases? Anyway, here is the forked repo, feel free to try it. I would be willing to make a PR if it does work, but I converted the android platform-specific code to Kotlin because I absolutely abhor Java. I'm not sure whether the author is okay with this change.

ramyajaganathan commented 2 years ago

I also have same issue . Have anyone solved the issue . How? please share