Missing foreground service type for API 34+
The apk that's produced with !74 (merged) keeps crashing
2023-12-12 12:53:36.173 23986-23986 AndroidRuntime org.torproject.vpn E FATAL EXCEPTION: main
Process: org.torproject.vpn, PID: 23986
java.lang.RuntimeException: Unable to start service org.torproject.vpn.vpn.TorVpnService@d8f08d with Intent { act=TorVpnService.start cmp=org.torproject.vpn/.vpn.TorVpnService }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{27138de 23986:org.torproject.vpn/u0a366} 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{27138de 23986:org.torproject.vpn/u0a366} 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 java.lang.reflect.Method.invoke(Native Method)
at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:93)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy3.setServiceForeground(Unknown Source)
at android.app.Service.startForeground(Service.java:775)
at org.torproject.vpn.vpn.TorVpnService.onStartCommand(TorVpnService.kt:79)
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)
2023-12-12 12:53:37.824 24022-24022 AndroidRuntime org.torproject.vpn E FATAL EXCEPTION: main
Process: org.torproject.vpn, PID: 24022
java.lang.RuntimeException: Unable to start service org.torproject.vpn.vpn.TorVpnService@2912a52 with Intent { act=TorVpnService.start cmp=org.torproject.vpn/.vpn.TorVpnService }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{4a097a7 24022:org.torproject.vpn/u0a366} 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{4a097a7 24022:org.torproject.vpn/u0a366} 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 java.lang.reflect.Method.invoke(Native Method)
at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:93)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy3.setServiceForeground(Unknown Source)
at android.app.Service.startForeground(Service.java:775)
at org.torproject.vpn.vpn.TorVpnService.onStartCommand(TorVpnService.kt:79)
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)
Edited by kwadronaut