microg/GmsCore · error · SecurityException

Neither android.permission.ACCESS_COARSE_LOCATION nor androi

Error message

Neither android.permission.ACCESS_COARSE_LOCATION nor android.permission.ACCESS_FINE_LOCATION granted.

What it means

GoogleMapImpl.setMyLocationEnabled mirrors the Google Maps SDK contract: showing the user's location requires a location permission. microG checks for ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION at call time and throws a SecurityException when neither is granted. The feature is otherwise not yet implemented in the vtm backend (a warning is logged).

Source

Thrown at play-services-maps/core/vtm/src/main/java/org/microg/gms/maps/vtm/GoogleMapImpl.java:518

    }

    @Override
    public void setIndoorEnabled(boolean indoor) throws RemoteException {
        Log.w(TAG, "Indoor not yet supported");
    }

    @Override
    public boolean isMyLocationEnabled() throws RemoteException {
        return false;
    }

    @Override
    public void setMyLocationEnabled(boolean myLocation) throws RemoteException {
        Log.w(TAG, "MyLocation not yet supported");
        boolean hasPermission = ContextCompat.checkSelfPermission(context, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED
                || ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED;
        if (!hasPermission) {
            throw new SecurityException("Neither " + ACCESS_COARSE_LOCATION + " nor " + ACCESS_FINE_LOCATION + " granted.");
        }
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (myLocation) {
            locationManager.requestLocationUpdates(5000, 10, criteria, listener, Looper.getMainLooper());
        } else {
            locationManager.removeUpdates(listener);
        }
    }

    @Override
    public boolean isBuildingsEnabled() throws RemoteException {
        return backendMap.hasBuilding();
    }

    @Override
    public void setBuildingsEnabled(boolean buildingsEnabled) throws RemoteException {
        backendMap.setBuildings(buildingsEnabled);
    }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> (and/or ACCESS_COARSE_LOCATION) to the manifest
  2. Request the permission at runtime with ActivityCompat.requestPermissions and check grantResults before calling setMyLocationEnabled
  3. Wrap the call and only enable the my-location layer when ContextCompat.checkSelfPermission returns PERMISSION_GRANTED

Example fix

// before
googleMap.setMyLocationEnabled(true);
// after
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    googleMap.setMyLocationEnabled(true);
} else {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQ_LOC);
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean granted = ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
    || ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
if (granted) googleMap.setMyLocationEnabled(true);

Try / catch

try { googleMap.setMyLocationEnabled(true); } catch (SecurityException e) { requestRuntimeLocationPermission(); }

Prevention

When it happens

Trigger: Calling googleMap.setMyLocationEnabled(true) from an app whose manifest lacks the permission or whose runtime permission was not granted (permission denied/revoked or never requested via ActivityCompat.requestPermissions).

Common situations: Adding a map with my-location layer while only having manifest permission but no runtime grant; testing on Android 6+ without runtime request; permission revoked by user or by system battery/privacy management.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/7d9088c52794ebab. Report an issue: GitHub.