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

Android Targeting S+ requires one of FLAG_IMMUTABLE or FLAG_MUTABLE specified when creating PendingIntent #2

Open
Franjoo opened this issue Mar 10, 2022 · 12 comments

Comments

@Franjoo
Copy link

Franjoo commented Mar 10, 2022

App crashes after fcm background notification was received.

Exception:

E/AndroidRuntime: FATAL EXCEPTION: Firebase-FcmMessageHandler
    Process: com.example.game, PID: 24585
    java.lang.IllegalArgumentException: com.example.game: 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.getActivityAsUser(PendingIntent.java:458)
        at android.app.PendingIntent.getActivity(PendingIntent.java:444)
        at android.app.PendingIntent.getActivity(PendingIntent.java:408)
        at com.google.firebase.messaging.zza.zzh(Unknown Source:124)
        at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:57)
        at com.google.firebase.iid.zzc.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
        at java.lang.Thread.run(Thread.java:920)

platform: Android (API 31)
gdxVersion = '1.10.0'
pushMsgsVersion = '1.0.0'

Thank you very much for providing this library 🤘

@MrStahlfelge
Copy link
Owner

Hi, looks like you are using Firebase's built-in capability to show the notification? Looks like they've fixed the issue: firebase/firebase-android-sdk#3115 => update fcm dependency in your project

(But i would rather recommend to write your own code showing notifications)

@Franjoo
Copy link
Author

Franjoo commented Mar 10, 2022

Correct, I want to use Firebase's built-in capability to show the notifications when the app is in background or closed (I am not planning to send data notifications). Therefore I added your gdx-pushmessages-android-fcm dependency.
That worked as expected before updating the target sdk.

I did not add the firebase-messaging additionally. That is correct right?

I noticed that you internally use firebase-messaging in version 17.3.4 which is pretty outdated (latest is 23.0.0). Could the issue perhaps be resolved by updating this dependency?

Thanks for your help!

@MrStahlfelge
Copy link
Owner

Could the issue perhaps be resolved by updating this dependency?

That's what I meant with "update fcm dependency in your project" :-)

You did not set it yourself so your project uses the version I used to compile this lib. You can use a newer one by adding it to your project yourself.

@Franjoo
Copy link
Author

Franjoo commented Mar 10, 2022

Okay, unfortunately I had no success with the dependency update. After I added

implementation 'com.google.firebase:firebase-messaging:23.0.0'

a new issue comes up that leads to an app crash on startup:

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
    at de.golfgl.gdxpushmessages.FcmMessageProvider.initService(FcmMessageProvider.java:54)
    at com.example.game.Main.initialize(Main.kt:247)
    at com.example.game.Main.render(Main.kt:296)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:471)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
Caused by java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/~~P3k_C2tJ6FtRT0doo3abBw==/com.example.game-TilkKXA9LiEkqm3Tby5BgQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~P3k_C2tJ6FtRT0doo3abBw==/com.example.game-TilkKXA9LiEkqm3Tby5BgQ==/lib/arm64, /data/app/~~P3k_C2tJ6FtRT0doo3abBw==/com.example.game-TilkKXA9LiEkqm3Tby5BgQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at de.golfgl.gdxpushmessages.FcmMessageProvider.initService(FcmMessageProvider.java:54)
    at com.example.game.Main.initialize(Main.kt:247)
    at com.example.game.Main.render(Main.kt:296)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:471)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)

As it looks to me, this is caused by the fact that Firebase InstanceId is deprecated / not available anymore in more recent sdk versions. It was replaced by Firebase Installations.

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId

So after all, I think that a Migration to the current messages api is the only way to come around this issue..

https://firebase.google.com/docs/projects/manage-installations#fid-iid

@MrStahlfelge
Copy link
Owner

Yes, looks like it.
My app using the feature is not on the Play Store anymore so I won't make the update, but if course I'll review and accept PRs.

@Franjoo
Copy link
Author

Franjoo commented Mar 10, 2022

I am not quite sure how to do the implementation / testing properly. Do you have an advice how I have to put the cloned local repo in my app (where I have a testing environment) 😬 i would be very thankful for some hints 😅

@MrStahlfelge
Copy link
Owner

Give a new version number and perform the step to compile to local maven repo. Then use this new version number in your project.

@Franjoo
Copy link
Author

Franjoo commented Mar 11, 2022

Seems like gradle wrapper configuration does not go along with the uploadArchives task..

Configuration on demand is an incubating feature.

> Configure project :android-fcm
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

> Task :core:compileJava FAILED
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:compileJava'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x30cbe3e7) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x30cbe3e7

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 754ms

@Franjoo
Copy link
Author

Franjoo commented Mar 11, 2022

Which project sdk should be used for the gradle jvm? How do I have to configure the project to archive from source?
Thanks again!

@MrStahlfelge
Copy link
Owner

GHA uses the same command and it works. :)
Did you use JDK8?

@MrStahlfelge
Copy link
Owner

Feel free to update SDK, Gradle etc when needed.

@Franjoo
Copy link
Author

Franjoo commented Mar 12, 2022

Got it!

java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x7021c5f8) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x7021c5f8

The above exception occurs when gradle does not use jdk 8 / a compatible jdk version
linked issue

Solution:

show current used jdk version
./gradlew --version

show all installed java versions

cd /usr/libexec
./java_home -V

(install jdk 8 via idea or 'by hand' if by hand if not present)

start gradle task with java home directory option pointing to working jdk version

./gradlew uploadArchives -PLOCAL=true -Dorg.gradle.java.home=/Users/{user}/Library/Java/JavaVirtualMachines/corretto-1.8.0_322/Contents/Home 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants