Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Status does not work correctly when in android release mode #227

Open
GabrielCoffee9 opened this issue Nov 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@GabrielCoffee9
Copy link

Is this a how to question?
No

Is this a native Spotify SDK issue?
No

Have you searched for existing issues?
Yes

Are you using a Free or Premium Spotify account?
Premium

Are you aware of the limitations of Free Spotify accounts?
Yes

Expected behavior
Connection Status subscription works in android release mode

Describe the bug
SpotifySdk.subscribeConnectionStatus() doesn't work when compiled in release mode on android.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Create a new Flutter application with Android platform
  2. Add Spotify_sdk package -> flutter pub add spotify_sdk
  3. Run auto setup for android -> dart run spotify_sdk:android_setup
  4. Run -> flutter build apk
  5. Try to listen the function SpotifySdk.subscribeConnectionStatus()
  6. Use the function SpotifySdk.connectToSpotifyRemote() to sign in
  7. Nothing happens (The connection status event is not working).

Spotify_sdk Flutter package version 3.0.2

Flutter version 3.24.3

spotify_sdk:
    dependency: "direct main"
    description:
      name: spotify_sdk
      sha256: "4c7a3b79f0370e7ae8ac07cad5e630d0bb3ad118f4c16219ec37f6988a65465e"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.2"

Target Platform, Version & Device

  • OS & Version: Tested Android 14 and 15
  • Device: Tested in Android Emulator Medium Phone API 34 and 35

Development OS

  • Windows

That bug only happens in release mode (on Android), where the Connection Status does not work correctly due to probably a parsing problem.

Found out that:

In the function ConnectionStatus _$ConnectionStatusFromJson(Map<String, dynamic> json) in the file:

"C:\Users{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.g.dart"

The parameter json is filled with keys:'a', 'b', 'c' and 'd' when in release mode, instead of 'connected', 'message', 'errorCode' and 'errorDetails'. The values are ok but the json keys are wrong.

As a temporary workaround I modified two files:

First, I added this import at the very top of the file: C:\Users\{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.dart

import 'package:flutter/foundation.dart';

Second, I modified this function on the file: C:\Users\{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.g.dart

ConnectionStatus _$ConnectionStatusFromJson(Map<String, dynamic> json) {
  if (kReleaseMode) {
    return ConnectionStatus(
      json['b'] as String?,
      json['c'] as String?,
      json['d'] as String?,
      connected: json['a'] as bool,
    );
  } else {
    return ConnectionStatus(
      json['message'] as String?,
      json['errorCode'] as String?,
      json['errorDetails'] as String?,
      connected: json['connected'] as bool,
    );
  }
}

After the changes ConnectionStatus seems to work properly.

@GabrielCoffee9 GabrielCoffee9 added the bug Something isn't working label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant