google / flutter.plugins

BSD 3-Clause "New" or "Revised" License
117 stars 55 forks source link

[Crash] All of the sudden my app started crashing and I cant even build it on Android Studio Anymore. #137

Closed arodriguezgb closed 1 year ago

arodriguezgb commented 1 year ago

``This crash is weird, it started all of the sudden , does anyone know what it could be ?

✓ Built build/app/outputs/flutter-apk/app-debug.apk. Installing build/app/outputs/flutter-apk/app.apk... E/AndroidRuntime(21677): FATAL EXCEPTION: main E/AndroidRuntime(21677): Process: gentlebirth.app, PID: 21677 E/AndroidRuntime(21677): java.lang.RuntimeException: Unable to create service com.google.flutter.plugins.audiofileplayer.AudiofileplayerService: java.lang.IllegalArgumentException: ComponentName does not belong to sessionPackageName. sessionPackageName = gentlebirth.app, ComponentName pkg = com.google.android.apps.youtube.music

Edit:

The crash seems to be only happening on my Pixel 6 Pro with Latest Update. Im not sure if its something wrong in the latest Android 13 update. Ill keep monitoring.

Edit 2:

The issue seems to be here, because if i comment everything inside OnCreate, the app builds but obviously the player doesn't work well. This is happening on Android 13 QPR1 Beta 2 and 3.

` @Override
  public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate");
    instance = this;
    PendingIntent pendingItent = PendingIntent.getBroadcast(
            getApplicationContext(),
            0, new Intent(Intent.ACTION_MEDIA_BUTTON),
            PendingIntent.FLAG_IMMUTABLE
    );

mediaSession = new MediaSessionCompat(this, TAG, null, pendingItent);
mediaSession.setFlags(
    MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
        | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
PlaybackStateCompat.Builder stateBuilder =
    new PlaybackStateCompat.Builder()
        .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE);
mediaSession.setPlaybackState(stateBuilder.build());

mediaSessionCallback = new MediaSessionCallback(); // Do i need this as ivar?
mediaSession.setCallback(mediaSessionCallback);

setSessionToken(mediaSession.getSessionToken());

} `

arodriguezgb commented 1 year ago

This is still happening. I have no idea what it can be.

arodriguezgb commented 1 year ago
Changing the mediasessioncompat to this mediaSession = new MediaSessionCompat(this, TAG); from this     mediaSession = new MediaSessionCompat(this, TAG, null, pendingItent);

Fixes this crash. The component name being null is "MAYBE" whats causing it.

arodriguezgb commented 1 year ago

Im sure this can be fixed properly but Im not sure how. @monkeyswarm I just debugged a bit till I found the offending part.

monkeyswarm commented 1 year ago

I'll take a look. I'm guessing we want to switch from MediaSessionCompat to MediaSession.

I'm guessing this deprecation is somehow involved : https://developer.android.com/reference/android/media/session/MediaSession#setMediaButtonReceiver(android.app.PendingIntent) and that we will want to specify a BroadcastReceiver in the manifest.

Can you find any behavior that is no longer supported with your fix? I forget what the use case was for that pending intent, the docs imply that it's for hardware buttons (i.e. on headsets).

monkeyswarm commented 1 year ago

I submitted https://github.com/google/flutter.plugins/pull/138 with your suggested change; let me know if this creates any new issues, thanks.

arodriguezgb commented 1 year ago

I will test today with headsets etc to see if there is something not working as expected but with the phone itself its all working fine.