daily-co / react-native-daily-js

https://docs.daily.co/reference/rn-daily-js
BSD 2-Clause "Simplified" License
36 stars 13 forks source link

BUG: App immediately crashes when joining call (targeting android API version 34) #50

Closed nHussain18 closed 8 months ago

nHussain18 commented 8 months ago

Describe the bug (unexpected behavior)

FATAL EXCEPTION: main   
Process: com.___________, PID: 2235
java.lang.RuntimeException: Unable to start service com.daily.reactlibrary.DailyOngoingMeetingForegroundService@624e5f7 with Intent { cmp=com.___________/com.daily.reactlibrary.DailyOngoingMeetingForegroundService (has extras) }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{1ec1b4 2235:com.___________/u0a228} targetSDK=34
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839)
    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8177)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{1ec1b4 2235:com.___________/u0a228} targetSDK=34
    at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)

    at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
    at android.os.Parcel.readParcelableInternal(Parcel.java:4870)
    at android.os.Parcel.readParcelable(Parcel.java:4852)
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3052)
    at android.os.Parcel.createException(Parcel.java:3041)
    at android.os.Parcel.readException(Parcel.java:3024)
    at android.os.Parcel.readException(Parcel.java:2966)
    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
    at android.app.Service.startForeground(Service.java:775)
    at com.daily.reactlibrary.DailyOngoingMeetingForegroundService.onStartCommand(DailyOngoingMeetingForegroundService.java:89)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821)
    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:205) 
    at android.os.Looper.loop(Looper.java:294) 
    at android.app.ActivityThread.main(ActivityThread.java:8177) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

Steps to reproduce

  1. Set react native project to target android API version 34
  2. Run on a physical device running android 14
  3. Try to join a daily call
  4. Immediately crashes

System information

* Device: Samsung A33, Pixel6a * OS, version: android 14
nHussain18 commented 8 months ago

also getting this error log in android studio logcat

java.lang.RuntimeException: Unable to start service com.daily.reactlibrary.DailyOngoingMeetingForegroundService@12b090e with Intent { cmp=com.________/com.daily.reactlibrary.DailyOngoingMeetingForegroundService (has extras) }: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839)
   at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loopOnce(Looper.java:205)
   at android.os.Looper.loop(Looper.java:294)
   at android.app.ActivityThread.main(ActivityThread.java:8177)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
   at android.content.ComponentName.<init>(ComponentName.java:133)
   at android.content.Intent.<init>(Intent.java:7650)
   ....
filipi87 commented 8 months ago

Hi @nHussain18, thank you for reporting this.

I was able to repro that the issue is happening when targeting android API version 34. I opened a task so we can fix this.

filipi87 commented 8 months ago

Hi @nHussain18, When targeting Android version 34, Android has changed how the foreground services are working.  Now we need to require specific permissions for each type of foreground service.

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

Another difference is that we can not use the same foreground service for different purposes, for instance, keep a video call in background and start a media projection.

Additionally, before starting the foreground service, the user needs to have already accepted all the required permissions, including a new one POST_NOTIFICATIONS, that allows to show the foreground service notification.

For more details, refer to: Android Developer Documentation

We plan to address this issue in the upcoming version of react-native-daily-js and update our demo to target Android version 34. I will let you know once both changes have been published.

darrelladjei commented 8 months ago

Hey there, just wondering if there has been another update on this? @filipi87

filipi87 commented 8 months ago

We have already merged https://github.com/daily-co/react-native-webrtc/pull/40 to integrate the latest changes from react-native-webrtc into our fork.

And the next version of react-native-daily-js, 0.59.0, will already support targetting Android ap version 34. It will be required to also use our latest react-native-webrtc version, 118.0.3-daily.1, in order to work.

darrelladjei commented 8 months ago

Thanks, will @daily-co/config-plugin-rn-daily-js also be getting an upgrade? specifically will it be made to support expo 50?

filipi87 commented 8 months ago

Yes, we already have PRs up for both:

They are just waiting for react-native-daily-js, 0.59.0, which we should publish probably later this week or early next week.

filipi87 commented 8 months ago

Hi, the react-native-daily-js 0.59.0 is now available.

In order for targeting Android version 34 you will need use the latests versions of our SDKs:

"@daily-co/react-native-daily-js": "^0.59.0",
"@daily-co/react-native-webrtc": "^118.0.3-daily.1", 

Add the new permissions, and add the foreground service type camera|microphone inside AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

...

<service
  android:name="com.daily.reactlibrary.DailyOngoingMeetingForegroundService"
  android:exported="false"
  android:foregroundServiceType="camera|microphone"
/>

More details can be found in this commit, where we have added support in our playground app.

darrelladjei commented 8 months ago

Thanks for the push, but I'm getting a weird error after the migration:

TypeError: Super expression must either be null or a function, js engine: hermes

Its referencing the use of super in MediaStreamTrackEvent class. This is in an Expo project btw.

Might be due to react-native upgrade? Which as required by expo 50.

darrelladjei commented 8 months ago

For debugging this is my package.json


{
  "dependencies": {
    "@config-plugins/react-native-webrtc": "^8.0.0",
    "@daily-co/config-plugin-rn-daily-js": "^0.0.4",
    "@daily-co/react-native-daily-js": "^0.59.0",
    "@daily-co/react-native-webrtc": "118.0.3-daily.1",
    "@expo/webpack-config": "^19.0.0",
    "@react-native-async-storage/async-storage": "1.21.0",
    "@react-native-community/blur": "^4.4.0",
    "@react-native-community/slider": "4.4.2",
    "@react-native-vector-icons/zocial": "^1.1.1-alpha.3",
    "@react-navigation/bottom-tabs": "^6.5.11",
    "@react-navigation/material-top-tabs": "^6.6.5",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.16",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.8",
    "@types/lodash": "^4.14.202",
    "axios": "^1.6.2",
    "base-64": "^1.0.0",
    "dayjs": "^1.11.10",
    "expo": "^50.0.14",
    "expo-av": "~13.10.5",
    "expo-build-properties": "^0.11.0",
    "expo-constants": "~15.4.5",
    "expo-dev-client": "~3.3.11",
    "expo-device": "~5.9.3",
    "expo-file-system": "~16.0.8",
    "expo-image-picker": "~14.7.1",
    "expo-linear-gradient": "^12.7.2",
    "expo-linking": "~6.2.2",
    "expo-localization": "~14.8.3",
    "expo-module-scripts": "^3.4.0",
    "expo-notifications": "~0.27.6",
    "expo-splash-screen": "~0.26.4",
    "expo-status-bar": "~1.11.1",
    "expo-web-browser": "^12.8.1",
    "inversify": "^6.0.2",
    "libphonenumber-js": "^1.10.51",
    "lodash": "^4.17.21",
    "moment": "^2.29.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.73.6",
    "react-native-auth0": "^3.1.0",
    "react-native-background-timer": "^2.4.1",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-gesture-handler": "~2.14.0",
    "react-native-get-random-values": "^1.11.0",
    "react-native-image-colors": "^2.4.0",
    "react-native-incall-manager": "^4.1.0",
    "react-native-modal": "^13.0.1",
    "react-native-pager-view": "^6.2.0",
    "react-native-purchases": "^7.22.0",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-svg": "^14.1.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-vector-icons": "^10.0.3",
    "react-native-web": "~0.19.6",
    "reflect-metadata": "^0.1.13",
    "socket.io-client": "^4.7.2",
    "ts-hooks": "^0.1.0-rc8",
    "usehooks-ts": "^2.16.0"
  },
}
``
filipi87 commented 8 months ago

Hi @darrelladjei,

I tried to reproduce the issue in our demo app, which is also using Expo 50, but I have not been able to reproduce it. Even after changing all versions to match the same ones that you were using:

  "@config-plugins/react-native-webrtc": "^8.0.0",
  "@daily-co/config-plugin-rn-daily-js": "0.0.4",
  "@daily-co/react-native-daily-js": "^0.59.0",
  "@daily-co/react-native-webrtc": "^118.0.3-daily.1",
  "@react-native-async-storage/async-storage": "^1.21.0",
  "expo": "~50.0.14",
  "expo-build-properties": "~0.11.1",
  "expo-dev-client": "~3.3.11",
  "expo-splash-screen": "~0.26.4",
  "expo-status-bar": "~1.11.1",
  "react": "18.2.0",
  "react-native": "0.73.6",
  "react-native-background-timer": "^2.4.1",
  "react-native-get-random-values": "^1.11.0"

Are you able to reproduce it using our demo ? https://github.com/daily-demos/daily-expo-demo

If you still face the issue, I would recommend:

darrelladjei commented 8 months ago

Thanks for response, i've identified issue. This commit added event-target-shim as dependency. I was on 5.0.1. Upgrading to same version as your demo app fixed the issue.

darrelladjei commented 8 months ago

Hey @filipi87 shouldn't the config plugin also set the service type field? Doesn't seem to be and still getting errors on android.

filipi87 commented 8 months ago

Hi @darrelladjei , thank you for catching this. We should add this service type in our config plugin as well. I wonder why we haven't faced an issue with our demo app. I will push a fix for it and release a new version.

filipi87 commented 8 months ago

Hi @darrelladjei, published a new version. More details in this PR.

Let me know in case you face any issue.

nHussain18 commented 8 months ago

Hey @filipi87, is there any way to get call duration ?