carp-dk / carp-dk/flutter-plugins

[carp_background_location: 4.0.0] App crash when "start" in release mode (Android device)

Open
#806 0 comments 0 reactions 0 assignees View on GitHub
bugfix
Dominant language
Dart
Stars
608
Forks
735
Avg merge
1m
Merged PRs (30d)
3

Description

**Remember to specify the plugin name in the title!**
- carp_background_location: ^4.0.0
- permission_handler: ^11.0.0
- BuildGradle: [8.1.1]
- Flutter: [3.13.2]
- Dart: [3.1.0]

### Device / Emulator and OS
- Device: [Xiaomi Redmi 10A]
- OS: [Android 11]

### Flutter doctor
```
[✓] Flutter (Channel stable, 3.13.2, on macOS 13.5.2 22G91 darwin-x64, locale es-419)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 4.1)
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
[✓] VS Code (version 1.81.1)
[✓] Connected device (3 available)
[✓] Network resources

```

### Describe the bug
App crash when click on "start" button, in "release" mode.
In "debug" mode it works correctly.
I have only tested on an Android device.

### Bug log
```
E/AndroidRuntime(28497): FATAL EXCEPTION: main
E/AndroidRuntime(28497): Process: com.luis.carielo.my_back_locator_app, PID: 28497
E/AndroidRuntime(28497): java.lang.RuntimeException: Unable to start service yukams.app.background_locator_2.IsolateHolderService@6a7c267 with Intent { act=START cmp=com.luis.carielo.my_back_locator_app/yukams.app.background_locator_2.IsolateHolderService (has extras) }: java.lang.RuntimeException: Missing type parameter.
E/AndroidRuntime(28497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4526)
E/AndroidRuntime(28497): at android.app.ActivityThread.access$2200(ActivityThread.java:263)
E/AndroidRuntime(28497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2095)
E/AndroidRuntime(28497): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(28497): at android.os.Looper.loop(Looper.java:236)
E/AndroidRuntime(28497): at android.app.ActivityThread.main(ActivityThread.java:8097)
E/AndroidRuntime(28497): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28497): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
E/AndroidRuntime(28497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
E/AndroidRuntime(28497): Caused by: java.lang.RuntimeException: Missing type parameter.
E/AndroidRuntime(28497): at o3.a.d(SourceFile:1)
E/AndroidRuntime(28497): at o3.a.(SourceFile:1)
E/AndroidRuntime(28497): at yukams.app.background_locator_2.d$a$a.(Unknown Source:0)
E/AndroidRuntime(28497): at yukams.app.background_locator_2.d$a.b(SourceFile:1)
E/AndroidRuntime(28497): at a5.d.a(SourceFile:1)
E/AndroidRuntime(28497): at yukams.app.background_locator_2.IsolateHolderService.s(SourceFile:1)
E/AndroidRuntime(28497): at yukams.app.background_locator_2.IsolateHolderService.t(SourceFile:1)
E/AndroidRuntime(28497): at yukams.app.background_locator_2.IsolateHolderService.onStartCommand(Unknown Source:118)
E/AndroidRuntime(28497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4503)
E/AndroidRuntime(28497): ... 8 more
```

### Code
```
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:carp_background_location/carp_background_location.dart';

void main() => runApp(MyApp2());

class MyApp2 extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

enum LocationStatus { UNKNOWN, INITIALIZED, RUNNING, STOPPED }

class _MyAppState extends State {
String logStr = '';
LocationDto? _lastLocation;
StreamSubscription? locationSubscription;
LocationStatus _status = LocationStatus.UNKNOWN;

@override
void initState() {
super.initState();

LocationManager().interval = 60;
LocationManager().distanceFilter = 0;
LocationManager().notificationTitle = 'CARP Location Example';
LocationManager().notificationMsg = 'CARP is tracking your location';

_status = LocationStatus.INITIALIZED;
}

void getCurrentLocation() async => onData(await LocationManager().getCurrentLocation());

void onData(LocationDto location) {
print('>> $location');
setState(() {
_lastLocation = location;
});
}

/// Is "location always" permission granted?
Future isLocationAlwaysGranted() async => await Permission.locationAlways.isGranted;

/// Tries to ask for "location always" permissions from the user.
/// Returns `true` if successful, `false` otherwise.
Future askForLocationAlwaysPermission() async {
bool granted = await Permission.locationAlways.isGranted;
PermissionStatus? granted2; // Added.

if (!granted) {
granted2 = await Permission.location.request(); // Added.

// Added.
if (granted2 == PermissionStatus.granted) {
granted = await Permission.locationAlways.request() == PermissionStatus.granted;
}
}

return granted;
}

/// Start listening to location events.
void start() async {
// ask for location permissions, if not already granted
if (!await isLocationAlwaysGranted()) await askForLocationAlwaysPermission();

locationSubscription?.cancel();
locationSubscription = LocationManager().locationStream.listen(onData);
await LocationManager().start();
setState(() {
_status = LocationStatus.RUNNING;
});
}

void stop() {
locationSubscription?.cancel();
LocationManager().stop();
setState(() {
_status = LocationStatus.STOPPED;
});
}

Widget stopButton() => SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('STOP'),
onPressed: stop,
),
);

Widget startButton() => SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('START'),
onPressed: start,
),
);

Widget statusText() => Text("Status: ${_status.toString().split('.').last}");

Widget currentLocationButton() => SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('CURRENT LOCATION'),
onPressed: getCurrentLocation,
),
);

Widget locationWidget() {
if (_lastLocation == null)
return Text("No location yet");
else
return Column(
children: [
Text(
'${_lastLocation!.latitude}, ${_lastLocation!.longitude}',
),
Text(
'@',
),
Text('${DateTime.fromMillisecondsSinceEpoch(_lastLocation!.time ~/ 1)}')
],
);
}

@override
void dispose() => super.dispose();

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('CARP Background Location'),
),
body: Container(
width: double.maxFinite,
padding: const EdgeInsets.all(22),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
startButton(),
stopButton(),
currentLocationButton(),
Divider(),
statusText(),
Divider(),
locationWidget(),
],
),
),
),
),
);
}
}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.