flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[Bug]: Missing permissions required by NotificationManagerCompat.notify

Open Huber1 opened this issue 1 year ago • 18 comments

Please check the following before submitting a new issue.

Please select affected platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Steps to reproduce

  1. Go to android directory
  2. Run ./gradlew clean
  3. Run ./gradlew build

Expected results

App builds normally

Actual results

Task :geolocator_android:lintDebug FAILED Lint found 1 errors, 4 warnings. First failure:

/home/moritz/.pub-cache/hosted/pub.dev/geolocator_android-4.4.0/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: /home/moritz/IdeaProjects/better_hm/build/geolocator_android/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

  • 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:
              ```
              android {
                  lint {
                      baseline = file("lint-baseline.xml")
                  }
              }
              ```

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

              Lint found 1 errors, 4 warnings. First failure:

/home/moritz/.pub-cache/hosted/pub.dev/geolocator_android-4.4.0/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: /home/moritz/IdeaProjects/better_hm/build/geolocator_android/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt


lint-results-debug.txt

Code sample

Not necessary

Screenshots or video

No response

Version

10.1.0 --> geolocator_android: 4.4.0

Flutter Doctor output

[✓] Flutter (Channel stable, 3.16.2, on openSUSE Tumbleweed 6.6.2-1-default, locale en_US.UTF-8) • Flutter version 3.16.2 on channel stable at /usr/local/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 9e1c857886 (6 days ago), 2023-11-30 11:51:18 -0600 • Engine revision cf7a9d0800 • Dart version 3.2.2 • DevTools version 2.28.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at /home/moritz/Android/Sdk • Platform android-33, build-tools 33.0.2 • Java binary at: /home/moritz/.local/share/JetBrains/Toolbox/apps/android-studio/jbr/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop • clang version 17.0.5 • cmake version 3.27.7 • ninja version 1.11.1 • pkg-config version 1.8.0

[✓] Android Studio (version 2023.1) • Android Studio at /home/moritz/.local/share/JetBrains/Toolbox/apps/android-studio • Flutter plugin version 76.3.3 • Dart plugin version 222.4582 • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2) • IntelliJ at /home/moritz/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate • Flutter plugin version 76.3.4 • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.84.0) • VS Code at /usr/share/code • Flutter extension can be installed from: 🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available) • Linux (desktop) • linux • linux-x64 • openSUSE Tumbleweed 6.6.2-1-default

[✓] Network resources • All expected network resources are available.

! Doctor found issues in 1 category.

Huber1 avatar Dec 06 '23 17:12 Huber1

Dear @Huber1,

Do you still have this issue? I cannot reproduce this.

Kind regards,

Tim

TimHoogstrate avatar Jan 04 '24 10:01 TimHoogstrate

Hi Tim, I am currently on vacation so I can tell you next week. Thanks for your work on this package

Huber1 avatar Jan 04 '24 11:01 Huber1

I'll close this for now, don't get this error ATM. If I get it again, I'll reopen the issue. Thanks for your awesome work on this package

Huber1 avatar Jan 13 '24 16:01 Huber1

Error: Missing permissions required by NotificationManagerCompat.notify: android.permission.POST_NOTIFICATIONS [MissingPermission] notificationManager.notify(notificationId, builder.build()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Explanation for issues of type "MissingPermission":

gellsonmesquita avatar Feb 07 '24 01:02 gellsonmesquita

how can i solve this ? the error is same above

gellsonmesquita avatar Feb 07 '24 01:02 gellsonmesquita

Any updates on this? I'm running into the same problem as OP

Demented-Elmo avatar Sep 11 '24 03:09 Demented-Elmo

This is not a final solution, but for the moment works to me: I change the version of gradle to this one: distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-all.zip

/android/build.gradle --->

ext.kotlin_version = '1.8.0'
dependencies {
        classpath ('com.android.tools.build:gradle:7.4.2')
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
    }

// I think this is specific config only for the packages that I'm using

configurations.all {
        resolutionStrategy.eachDependency { details ->
            def requested = details.requested
            
            if (requested.group == "androidx.webkit" && requested.name == "webkit") {
                details.useVersion "1.6.0"
            }
            
            if (requested.group == "androidx.window" && requested.name == "window") {
                details.useVersion "1.0.0"
            }
            if (requested.group == "androidx.window" && requested.name == "window-java") {
                details.useVersion "1.0.0"
            }
            
            if (requested.group == "androidx.fragment" && requested.name == "fragment") {
                details.useVersion "1.6.0"  
            }
            
            if (requested.group == "androidx.lifecycle" && requested.name.startsWith("lifecycle-")) {
                details.useVersion "2.6.0"  
            }
            
            if (requested.group == "androidx.core" && (requested.name == "core" || requested.name == "core-ktx")) {
                details.useVersion "1.8.0"  
            }

            
            if (requested.group == "androidx.annotation" && requested.name == "annotation-experimental") {
                details.useVersion "1.3.0"  
            }

            if (requested.group == "androidx.activity" && requested.name == "activity") {
                details.useVersion "1.7.0"  
            }
        }
    }

/android/app/build.gradle --->

compileSdkVersion 33
minSdkVersion 21
targetSdkVersion 33

/settings.gradle --->

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '7.4.2' apply false
    id "org.jetbrains.kotlin.android" version "1.8.0" apply false
}

I hope that works to you, It is a solution in the meantime

CarlosAlvarezdev avatar Oct 04 '24 12:10 CarlosAlvarezdev

Can you reopen this issue? I'm facing this issue.

geolocator_android-4.3.1/android/src/main/java/com/baseflow/geolocator/location/BackgroundNotification.java:93: Error: Missing permissions required by NotificationManagerCompat.notify: android.permission.POST_NOTIFICATIONS [MissingPermission]
            notificationManager.notify(notificationId, builder.build());
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Version: geolocator: ^10.1.0

app/build.gradle

buildscript {
    ext.kotlin_version = '1.8.0'
    //Needed for BackgroundFetch Flutter package
    ext {
        compileSdkVersion   = 34                // or higher
        targetSdkVersion    = 34                // or higher
        appCompatVersion    = "1.1.0"           // or higher
    }
    //
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // Add the google services classpath
        classpath 'com.google.gms:google-services:4.3.15'
        //Crashlytics
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

geeksilva97 avatar Nov 19 '24 01:11 geeksilva97

I am also facing this issue in version 4.6.1

damianr13 avatar Jan 06 '25 15:01 damianr13

same issue

vorn-dev-ni avatar Feb 06 '25 10:02 vorn-dev-ni

@TimHoogstrate I'm having this same issue as well and it seems others still are also, can this be reopened?

I believe this PR fixes it.. can you merge it in?? https://github.com/Baseflow/flutter-geolocator/pull/1593

MyBlueford16 avatar Feb 12 '25 23:02 MyBlueford16

i reopened this now, because others still have the problem

Huber1 avatar Feb 12 '25 23:02 Huber1

I am also having this issue. i tried a lot of different ways but nothings working. if i get a solution ill update it here.

AromalSk avatar Mar 06 '25 05:03 AromalSk

Can someone confirm if this is still happening in the latest versions? Because I still cannot reproduce this.

Kind regards

TimHoogstrate avatar Mar 20 '25 14:03 TimHoogstrate

I'm unfortunately still having this issue, even after an update to the last version of geolocator (13.0.3). I'm using https://services.gradle.org/distributions/gradle-8.1-all.zip (but same issue with 8.0)

LJaschinski avatar Mar 25 '25 15:03 LJaschinski

Can anyone put their updated flutter doctor -v output here. Because I still cannot reproduce this.

TimHoogstrate avatar Apr 07 '25 07:04 TimHoogstrate

I have the same issue. Here's my flutter doctor -v (lauched without any device connected)

[✓] Flutter (Channel stable, 3.29.1, on Ubuntu 22.04.5 LTS 6.8.0-52-generic, locale en_US.UTF-8) [50ms]
    • Flutter version 3.29.1 on channel stable at /home/pc-004/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 09de023485 (6 weeks ago), 2025-02-28 13:44:05 -0800
    • Engine revision 871f65ac1b
    • Dart version 3.7.0
    • DevTools version 2.42.2

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [132ms]
    • Android SDK at /home/pc-004/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/linux-android-setup for more details.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) [19ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop [513ms]
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2024.1) [17ms]
    • Android Studio at /snap/android-studio/161
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.98.2) [15ms]
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension version 3.106.0

[✓] Connected device (1 available) [93ms]
    • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.5 LTS 6.8.0-52-generic

[✓] Network resources [266ms]
    • All expected network resources are available.

TitouanLrav avatar Apr 08 '25 14:04 TitouanLrav

I also have this issue, has anyone fixed it already I have tried everything and nothing is fixing it

bername avatar Jun 04 '25 07:06 bername