Closed GarvinChanderia closed 4 months ago
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)
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.
Get more help at https://help.gradle.org
BUILD FAILED in 51s Error: Gradle task assembleDebug failed with exit code 1
@GarvinChanderia does using the version of the code on the main branch (not pub.dev) solve the issue for you?
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"); });
}