gokadzev / capacitor-music-controls-plugin-new

An update to Cordova Music Controls plugin to support Capacitor 3
9 stars 4 forks source link

PendingIntent: Targeting S+ (version 31 and above) requires FLAG_IMMUTABLE or FLAG_MUTABLE #8

Closed sanderschnydrig closed 2 years ago

sanderschnydrig commented 2 years ago

I'm using Angular 12 with Capacitor and this Plugin, set the compileSdkVersion and targetSdkVersion to 31 in variables.gradle (I prefer not to put them to 31 as this can cause a lot of issues down the line). When I start the app on Android I get this error:

 Caused by: java.lang.IllegalArgumentException: ch.pomona.newsapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
        at com.gokadzev.capacitormusiccontrols.MusicControlsNotification.createBuilder(MusicControlsNotification.java:209)
        at com.gokadzev.capacitormusiccontrols.MusicControlsNotification.updateNotification(MusicControlsNotification.java:81)
        at com.gokadzev.capacitormusiccontrols.CapacitorMusicControls.updateMetadata(CapacitorMusicControls.java:224)
        at com.gokadzev.capacitormusiccontrols.CapacitorMusicControls.create(CapacitorMusicControls.java:42)
            ... 9 more

I solved it by reverting back to API level 30 instead of 31 and forcing the androidx.appcompat dependency to version 1.2.0 (instead of 1.4.2 that will be picked otherwise):

in your app/build.gradle:

dependencies {
    implementation("androidx.appcompat:appcompat:$androidxAppCompatVersion") {
        force = true
    }
}
FloryanFilip commented 2 years ago

I tried that but I'm getting

        resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_MUTABLE);
                                                                                                   ^
  symbol:   variable FLAG_MUTABLE
  location: class PendingIntent

build error during gradle build process

sanderschnydrig commented 2 years ago

@FloryanFilip make sure you explicitly set the version ($androidxAppCompatVersion in my case) to 1.2.0, other than that I have no idea how to solve it in your case.

dependencies {
    implementation("androidx.appcompat:appcompat:1.2.0") {
        force = true
    }
}
gokadzev commented 2 years ago

@sanderschnydrig @FloryanFilip if problem will be still active after updating latest version tell me and i will change appcompat version in code.