Flutter - Error No location permissions are defined in the manifest
In flutter development, if you are fetching first-time Longitude or Latitude from a GPS or geolocation in your project then you may get a "No location permissions are defined in the manifest". We can easily solve this error "No location permissions are defined in the manifest" like below.
Error :
You can see below the full error message
E/flutter ( 8937): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
No location permissions are defined in the manifest. Make sure at
least ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION are defined in the manifest.
E/flutter ( 8937): #0 MethodChannelGeolocator.checkPermission
(package:geolocator_platform_interface/
src/implementations/method_channel_geolocator.dart:48:7)
E/flutter ( 8937): <asynchronous suspension>`
E/flutter ( 8937): #1 _HomeState.checkGps (package:testapp/main.dart:38:26)
E/flutter ( 8937): <asynchronous suspension>
E/flutter ( 8937):
Solutions :
To solve this error we need to add Location permission in AndroidManifest.xml which is located in android/app/src/main/AndroidManifest.xml.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Your AndroidManifest file may look like below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.errorgram">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:label="errorgram"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
We have to add ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permission to use Geolocation for Android App.
After adding these two permissions to the AndroidManifest.xml file, We need to run a clean command of the flutter.
clean
Finally, run your project...Wow, it's gone error. I hope this tutorial may help you.
Copyright 2024 ErrorGram