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

java.lang.RuntimeException: Unable to create service com.almoullim.background_location.LocationUpdatesService: java.lang.SecurityException: com.throttle.app.throttlemvp: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts #214

Closed
GarvinChanderia opened this issue Jun 14, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@GarvinChanderia
Copy link

This is an issue caused when using Android 14 Devices. Is there anything we can do to solve this?

Device: Pixel 6a (Physical)
Error:
D/AndroidRuntime(22315): Shutting down VM
E/AndroidRuntime(22315): FATAL EXCEPTION: main
E/AndroidRuntime(22315): Process: com.throttle.app.throttlemvp, PID: 22315
E/AndroidRuntime(22315): java.lang.RuntimeException: Unable to create service com.almoullim.background_location.LocationUpdatesService: java.lang.SecurityException: com.throttle.app.throttlemvp: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
E/AndroidRuntime(22315): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4878)
E/AndroidRuntime(22315): at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
E/AndroidRuntime(22315): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2365)
E/AndroidRuntime(22315): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(22315): at android.os.Looper.loopOnce(Looper.java:232)
E/AndroidRuntime(22315): at android.os.Looper.loop(Looper.java:317)
E/AndroidRuntime(22315): at android.app.ActivityThread.main(ActivityThread.java:8501)
E/AndroidRuntime(22315): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(22315): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime(22315): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
E/AndroidRuntime(22315): Caused by: java.lang.SecurityException: com.throttle.app.throttlemvp: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
E/AndroidRuntime(22315): at android.os.Parcel.createExceptionOrNull(Parcel.java:3182)
E/AndroidRuntime(22315): at android.os.Parcel.createException(Parcel.java:3166)
E/AndroidRuntime(22315): at android.os.Parcel.readException(Parcel.java:3149)
E/AndroidRuntime(22315): at android.os.Parcel.readException(Parcel.java:3091)
E/AndroidRuntime(22315): at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5784)
E/AndroidRuntime(22315): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1853)
E/AndroidRuntime(22315): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1793)
E/AndroidRuntime(22315): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1781)
E/AndroidRuntime(22315): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:756)
E/AndroidRuntime(22315): at com.almoullim.background_location.LocationUpdatesService.onCreate(LocationUpdatesService.kt:154)
E/AndroidRuntime(22315): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4865)
E/AndroidRuntime(22315): ... 9 more
E/AndroidRuntime(22315): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(22315): at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14337)
E/AndroidRuntime(22315): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2615)
E/AndroidRuntime(22315): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2798)
E/AndroidRuntime(22315): at android.os.Binder.execTransactInternal(Binder.java:1496)
E/AndroidRuntime(22315): at android.os.Binder.execTransact(Binder.java:1440)
E/AndroidRuntime(22315):
Lost connection to device.

code:

import 'dart:async';

import 'package:background_location/background_location.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
//import 'package:location/location.dart' ;
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'globalVariables.dart';

final service = FlutterBackgroundService();
LatLng? _pUserLoc;

Future getLocationUpdates() async{
WidgetsFlutterBinding.ensureInitialized();

BackgroundLocation.setAndroidConfiguration(1000);
BackgroundLocation.stopLocationService();
BackgroundLocation.startLocationService();

BackgroundLocation.getLocationUpdates((currentLocation) {
if(currentLocation.latitude != null &&
currentLocation.longitude != null){
_pUserLoc = LatLng(currentLocation.latitude!, currentLocation.longitude!);
updateDatabaseRide(_pUserLoc!);
if (kDebugMode) {
print(_pUserLoc);
}
}});

}

Future updateDatabaseRide(LatLng pos) async{
DatabaseReference ref = FirebaseDatabase.instance.ref("bikers/$rideCode/$userName");

await ref.update({
"lat": pos.latitude,
"lng": pos.longitude,
});
}

Future initializeService() async{
await service.configure(
iosConfiguration: IosConfiguration(
autoStart: true,
onForeground: onStart,
onBackground: onIosBackground,
),
androidConfiguration: AndroidConfiguration(
onStart: onStart,
isForegroundMode: true,
autoStart: true
)
);
}

@pragma('vm:entry-point')
Future onIosBackground(ServiceInstance service) async{
WidgetsFlutterBinding.ensureInitialized();
//DartPluginRegistrant.ensureInitialized();
return true;
}

@pragma('vm:entry-point')
void onStart(ServiceInstance service) async{
//DartPluginRegistrant.ensureInitialized();
if(service is AndroidServiceInstance){
service.on('setAsForeground').listen((event) {service.setAsForegroundService();});
}
service.on('stopService').listen((event) {service.stopSelf();});

Timer.periodic(const Duration(seconds: 1),(timer) async{
if(service is AndroidServiceInstance){
if(await service.isForegroundService()){
service.setForegroundNotificationInfo(title: "Foreground Notification", content: "If you see this, your phone is super sensitive");
}
}
getLocationUpdates();
if (kDebugMode) {
print("background service running");
}
service.invoke("update");
});

}

@MoralCode
Copy link
Collaborator

Thanks for reporting this issue!
It seems like issue #200 already mentions this issue so I'll close this as a duplicate.

Is there anything we can do to solve this?

Community help is definitely needed to help maintain this repo, especially testing changes as I can't do it by myself (see #188)

@MoralCode MoralCode added the duplicate This issue or pull request already exists label Jun 14, 2024
@MoralCode MoralCode closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@GarvinChanderia
Copy link
Author

I tried the solution provided, causing me to get this error:

e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:41 Const 'val' initializer should be a constant value
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:44 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:96:17 Unresolved reference: Utils
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:207:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:211:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:241:15 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:244:51 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:168:9 Unresolved reference: Utils
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:177:13 Unresolved reference: Utils
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:252:13 Unresolved reference: Utils
e: file:///C:/Users/chand/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:255:13 Unresolved reference: Utils

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':background_location:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details

  • 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.

BUILD FAILED in 51s
Error: Gradle task assembleDebug failed with exit code 1

@MoralCode
Copy link
Collaborator

@GarvinChanderia does using the version of the code on the main branch (not pub.dev) solve the issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants