livekit / client-sdk-flutter

Flutter Client SDK for LiveKit
https://docs.livekit.io
Apache License 2.0
229 stars 108 forks source link

[bug] Screen Share on Android target API 34+ crashes with security warning #524

Closed kNoAPP closed 4 days ago

kNoAPP commented 1 month ago

Describe the bug After Android API level 34 (impacting Android 14), screen-share functionality according to the LiveKit documentation results in an app crash event.

E/AndroidRuntime(16537): java.lang.RuntimeException: Unable to start service de.julianassmann.flutter_background.IsolateHolderService@ceb8b4b with Intent { act=START cmp=com.remotelegal.astra/de.julianassmann.flutter_background.IsolateHolderService }: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{5ba1ad5 16537:com.remotelegal.astra/u0a549} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 
E/AndroidRuntime(16537):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5053)
E/AndroidRuntime(16537):    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
E/AndroidRuntime(16537):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2390)
E/AndroidRuntime(16537):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(16537):    at android.os.Looper.loopOnce(Looper.java:232)
E/AndroidRuntime(16537):    at android.os.Looper.loop(Looper.java:317)
E/AndroidRuntime(16537):    at android.app.ActivityThread.main(ActivityThread.java:8501)
E/AndroidRuntime(16537):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16537):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime(16537):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
E/AndroidRuntime(16537): Caused by: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{5ba1ad5 16537:com.remotelegal.astra/u0a549} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 

To Reproduce Set the example app's build.gradle target SDK to 34 or higher (currently 31). This is reproducible despite the changes in https://github.com/livekit/client-sdk-flutter/pull/470.

Expected behavior Android API level 34+ should have instructions documented to fix this issue. Otherwise, a general warning about targeting API 34+ should be added to the documentation.

Platform information

No issues found!

kNoAPP commented 1 month ago

Please note, you can work around this issue by using a target of Android API 33.

zerowu49 commented 4 days ago

To do screenshare on Android, you need flutter_background package, then you also need to make sure in the AndroidManifest.xml that:

More detail you could check the code in this file

I've tried change the targetSdkVersion to 34 and it still works correctly! Hope this helps!

kNoAPP commented 4 days ago

Issue still present, but under a different error. Opening a new issue with video.

kNoAPP commented 4 days ago

See: https://github.com/livekit/client-sdk-flutter/issues/542