Flutter not displaying location permission request on production (Android)

I recently published a Flutter app on Google Play. It worked perfectly while developing, but the version published on Google Play never asks for location permissions. It marks location permission as permanentlyDenied automatically.

This is the function that should trigger the location permission request:

  _getUserLocation() {
    if(context.read<UserLocationCubit>().state == null) {
      Permission.locationWhenInUse.request().then((PermissionStatus permissionStatus) {
        // If permission granted (permanently or not)...
        if(permissionStatus != PermissionStatus.permanentlyDenied && permissionStatus != PermissionStatus.denied) {
          setState(() {
            locationDenied = false;
          });
          Geolocator.getCurrentPosition(
            locationSettings: const LocationSettings(
              accuracy: LocationAccuracy.high,
            ),
          ).then((Position position) {
            LatLng newPosition = LatLng(position.latitude, position.longitude);
            context.read<UserLocationCubit>().set(
              location: newPosition,
            );
            setState(() {
              userLocation = newPosition;
            });
          });
        } else { // If permission denied (permanently or not)...
          setState(() {
            locationDenied = true;
          });
        }
      });
    } else {
      /* More stuff */
    }
  }

locationDenied is a nullable bool? but right after installing my app from Google Play, this function is called and I see the screen as expected when locationDenied is true, and it can only be set as true by this function. Conclusion: my app is automatically denying location permissions by default, not even asking.

When I go to my app settings (right after that) I see the following:
Location permission not allowed

My pupspec.yaml is the following:

name: he_name_of_my_app
description: "The_name_of_my_app"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.9+9

environment:
  sdk: '>=3.4.0-268.0.dev <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  app_links: ^6.2.1
  bloc: ^8.1.4
  carousel_slider: ^5.0.0
  cupertino_icons: ^1.0.6
  flutter_bloc: ^8.1.6
  flutter_secure_storage: ^9.2.2
  flutter_svg: ^2.0.10+1
  geolocator: ^13.0.1
  get: ^4.6.6
  google_fonts: ^6.2.1
  google_maps_flutter: ^2.9.0
  http: ^1.2.2
  image_picker: ^1.1.2
  mobile_scanner: ^5.2.1
  permission_handler: ^11.3.1
  qr_flutter: ^4.1.0
  share_plus: ^10.0.2
  # syncfusion_flutter_charts: ^26.2.10
  syncfusion_flutter_pdfviewer: ^26.2.10
  url_launcher: ^6.3.0
  webview_flutter: ^4.9.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

  assets:
    - assets/images/
    - assets/documents/terms_and_conditions.pdf

After searching plenty of sites, none got me to the solution. This is what I tried:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:label="The_name_of_my_app"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        >
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="standard"
            android:taskAffinity=""
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <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>
        <meta-data
            android:name="flutter_deeplinking_enabled"
            android:value="true" />
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="my_api_key" />
    </application>
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
    </queries>
</manifest>

[Edit] Thanks to an answer on this post, I realized I can flutter run --release to replicate the behaviour on production mode without requesting an update directly on Google Play, what sped up everything. However, when I run that command I get the following error which, to be honest, I honest, I have no idea what it means:

PS C:\repositorios\wefood_front_2\wefood> flutter run --release Launching lib\main.dart on 2306EPN60G in release mode... I/flutter ( 824): apm_flutter timing: start _startDetect begin :1727485206639 isProduction: true I/flutter ( 824): apm_flutter timing : start _startDetect end 1s: totalFrameCount 0 supplyFrameCount60 lastFrames length 0 1727485207844 fps: 60.0 Running Gradle task 'assembleRelease'... 79,6s √ Built build\app\outputs\flutter-apk\app-release.apk (21.2MB) Installing build\app\outputs\flutter-apk\app-release.apk... 1.764ms

Flutter run key commands. h List all available interactive commands. c Clear the screen q Quit (terminate the application on the device). I/flutter (11816): [IMPORTANT:flutter/shell/platform/android/android_context_vk_impeller.cc(67)] Using the Impeller rendering backend (Vulkan). W/FlutterEngineCxnRegstry(11816): Attempted to register plugin (io.flutter.plugins.pathprovider.d@3a6620d) but it was already registered with this FlutterEngine (B3.c@2c5e5c2). W/FlutterEngineCxnRegstry(11816): Attempted to register plugin (h1.a@501fd3) but it was already registered with this FlutterEngine (B3.c@2c5e5c2). W/FlutterEngineCxnRegstry(11816): Attempted to register plugin (h1.a@c020710) but it was already registered with this FlutterEngine (B3.c@2c5e5c2). W/FlutterEngineCxnRegstry(11816): Attempted to register plugin (P3.f@472e62f) but it was already registered with this FlutterEngine (B3.c@2c5e5c2). D/FlutterGeolocator(11816): Creating service. D/FlutterGeolocator(11816): Binding to location service. D/FlutterGeolocator(11816): Flutter engine connected. Connected engine count 1 E/flutter (11816): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter (11816): #0 PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65) E/flutter (11816): E/flutter (11816): #1 getApplicationSupportDirectory (package:path_provider/path_provider.dart:78) E/flutter (11816): E/flutter (11816): #2 _localPath (package:google_fonts/src/file_io_desktop_and_mobile.dart:39) E/flutter (11816): E/flutter (11816): #3 _localFile (package:google_fonts/src/file_io_desktop_and_mobile.dart:44) E/flutter (11816): E/flutter (11816): #4 saveFontToDeviceFileSystem (package:google_fonts/src/file_io_desktop_and_mobile.dart:15) E/flutter (11816): E/flutter (11816): E/flutter (11816): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter (11816): #0 PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65) E/flutter (11816): E/flutter (11816): #1 getApplicationSupportDirectory (package:path_provider/path_provider.dart:78) E/flutter (11816): E/flutter (11816): #2 _localPath (package:google_fonts/src/file_io_desktop_and_mobile.dart:39) E/flutter (11816): E/flutter (11816): #3 _localFile (package:google_fonts/src/file_io_desktop_and_mobile.dart:44) E/flutter (11816): E/flutter (11816): #4 saveFontToDeviceFileSystem (package:google_fonts/src/file_io_desktop_and_mobile.dart:15) E/flutter (11816): E/flutter (11816): E/flutter (11816): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter (11816): #0 PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65) E/flutter (11816): E/flutter (11816): #1 getApplicationSupportDirectory (package:path_provider/path_provider.dart:78) E/flutter (11816): E/flutter (11816): #2 _localPath (package:google_fonts/src/file_io_desktop_and_mobile.dart:39) E/flutter (11816): E/flutter (11816): #3 _localFile (package:google_fonts/src/file_io_desktop_and_mobile.dart:44) E/flutter (11816): E/flutter (11816): #4 saveFontToDeviceFileSystem (package:google_fonts/src/file_io_desktop_and_mobile.dart:15) E/flutter (11816): E/flutter (11816): E/flutter (11816): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: MissingPluginException(No implementation found for method requestPermissions on channel flutter.baseflow.com/permissions/methods) E/flutter (11816): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332) E/flutter (11816): E/flutter (11816): #1 MethodChannelPermissionHandler.requestPermissions (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler.dart:80) E/flutter (11816): E/flutter (11816): #2 PermissionActions.request (package:permission_handler/permission_handler.dart:109) E/flutter (11816): E/flutter (11816): #3 _UserExploreState._getUserLocation. (package:wefood/views/user/user_explore.dart:46) E/flutter (11816):

Note: user_explore.dart is the screen I'm struggling with, and the error refers to line: " Permission.locationWhenInUse.request().then((PermissionStatus permissionStatus) { "

Any help would be extremely appreciated, considering that my app is already on air! Thank you in advance.

Upvotes: 2

Views: 879

Answers (3)

Ananya Bisen
Ananya Bisen

Reputation: 1

1- Add your permission inside application tag 2- check if proguard is configured properly for your application in the proguard-rules.pro 3- check locally by flutter run —release

Upvotes: 0

artemniy
artemniy

Reputation: 21

Maybe answers here can help, if you didn't check it already: https://github.com/Baseflow/flutter-permission-handler/issues/406

Upvotes: 1

Ajit Sharma
Ajit Sharma

Reputation: 205

Working on debug but not on production it can be due to multiple factors.

  1. Try to add inside application tag.
  2. Use proguard
  3. Check it locally by flutter run --release Hope it will help

Upvotes: 2

Related Questions