Skip to content

[Bug]: Post Permission Lint Error #1726

@Glutarios66

Description

@Glutarios66

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

  1. Run ./gradlew build --no-daemon --info --stacktrace
  2. Then error happens for geolocator_android

Expected results

I added Post Notifications Permission to my AndroidManifest but it seems to be a plugin isse or i dont know

Actual results

  • What went wrong:
    Execution failed for task ':geolocator_android:lintDebug'.

Lint found errors in the project; aborting build.

Fix the issues identified by lint, or create a baseline to see only new errors.
To create a baseline, run gradlew updateLintBaseline after adding the following to the module's build.gradle file:

android {
    lint {
        baseline = file("lint-baseline.xml")
    }
}

For more details, see https://developer.android.com/studio/write/lint#snapshot

Lint found 1 errors, 6 warnings. First failure:

C:\Users\tugba\AppData\Local\Pub\Cache\hosted\pub.dev\geolocator_android-5.0.1+1\android\src\main\java\com\baseflow\geolocator\location\BackgroundNotification.java:100: Error: Missing permissions required by NotificationManagerCompat.notify: android.permission.POST_NOTIFICATIONS [MissingPermission]
notificationManager.notify(notificationId, builder.build());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 Explanation for issues of type "MissingPermission":
 This check scans through your code and libraries and looks at the APIs
 being used, and checks this against the set of permissions required to
 access those APIs. If the code using those APIs is called at runtime, then
 the program will crash.

 Furthermore, for permissions that are revocable (with targetSdkVersion 23),
 client code must also be prepared to handle the calls throwing an exception
 if the user rejects the request for permission at runtime.

The full lint text report is located at:
C:\Users\tugba\Documents\prayer_buddy\build\geolocator_android\intermediates\lint_intermediate_text_report\debug\lintReportDebug\lint-results-debug.txt

  • Try:

Run with --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':geolocator_android:lintDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:293)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:128)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:116)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)

Code sample

Android Manifest:

main.dart:

void main() async {

WidgetsFlutterBinding.ensureInitialized();
await LocationService.initLocation();

WidgetsBinding.instance.addPostFrameCallback((_) {
final context = navigatorKey.currentContext;
if (context != null) {
requestNotificationPermission(context);
}
});
}

location_service.dart:
import 'package:flutter/foundation.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';

class LocationService {
static final ValueNotifier cityName =
ValueNotifier('Lade...');

static  Future<Position> _determinePosition() async {

bool serviceEnabled;
LocationPermission permission;

// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// Location services are not enabled don't continue
// accessing the position and request users of the
// App to enable the location services.
return Future.error('Location services are disabled.');
}

permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// Permissions are denied, next time you could try
// requesting permissions again (this is also where
// Android's shouldShowRequestPermissionRationale
// returned true. According to Android guidelines
// your App should show an explanatory UI now.
return Future.error('Location permissions are denied');
}
}

if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}

// When we reach here, permissions are granted and we can
// continue accessing the position of the device.
return await Geolocator.getCurrentPosition();
}

static Future initLocation() async {
try {

  Position position = await _determinePosition();
  

  List<Placemark> placemarks =
      await placemarkFromCoordinates(position.latitude, position.longitude);

  if (placemarks.isNotEmpty) {
    cityName.value = placemarks.first.locality ?? 'Unbekannt';
  }
} catch (e) {
  cityName.value = 'Fehler';
}

}
}

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

^14.0.1

Flutter Doctor output

Doctor output
[Paste your output here]

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work list.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions