How to solve permission handler error in flutter?

2,353

Solution 1

Try flutter clean, delete the pubspec.lock file. Then run flutter pub get and then flutter run. It should resolve the issue.

Solution 2

Changing the compileSdkVersion to 30 or 31 in android\app\build.gradle can fix this issue

Share:
2,353
shanmkha
Author by

shanmkha

Updated on January 02, 2023

Comments

  • shanmkha
    shanmkha over 1 year

    Not sure where I made mistake but I got error while implementing permission_handler: ^7.1.0 ,the error message is ``` C:\src\flutter.pub-cache\hosted\http://pub.dartlang.org\permission_handler-7.2.0\android\src\main\java\com\baseflow\permissionhandler\ServiceManager.java:152: warning: [deprecation] getDefaultAdapter() in BluetoothAdapter has been deprecated final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); ^ error: warnings found and -Werror specified 1 error 1 warning

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for 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 1m 10s Exception: Gradle task assembleDebug failed with exit code 1 ``` Below I attached necessary screenshots flutter doctor -v And I also given permission in Androidmanifest

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    

    And compileSdkVersion 31, minSdkVersion 21, targetSdkVersion 30. Hope I have given all necessary details. If anything need please comment and please help to solve this issue and I don’t want to change my sdk version. Thank you in Advance.

  • shanmkha
    shanmkha over 2 years
    No @kaushik still getting same error
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    In pubspec.yaml file give permission_handler:any and try once please
  • shanmkha
    shanmkha over 2 years
    Iam getting same error dude @kaushik
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    Paste the full error here.
  • shanmkha
    shanmkha over 2 years
    After permission_handler: any and doing flutter clean , delete the pubspec.lock file. Then run flutter pub get and then flutter run , it working fine without any error.but how can I know which version it is using because we gave it as “any”?
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    Run flutter pub outdated. It will list all packages and it's versions too
  • shanmkha
    shanmkha over 2 years
    Hey @Kaushik I posed another question can you please go through this link. Thank You.