android react-native avoiding "Background location access not declared" in Google approval process

Viewed 4684

Okay, so Google is telling us "Background location access not declared" and not letting us publish our app. We have no use for background location, so we're trying to elimiate it completely.

Of course my manifest doesn't have it:

    <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" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-feature android:name="android.hardware.location.gps"/>

I've searched absolutely everywhere for anything that could be adding ACCESS_BACKGROUND_LOCATION to our app, and found nothing.

Using the silver searcher:

ag ACCESS_BACKGROUND_LOCATION .

I've exampined the blame report for a clue, and worked backwards on anything with the word 'background', to no avail: android/app/build/intermediates/manifest_merge_blame_file/myAppRelease/manifest-merger-blame-myapp-release-report.txt

I did find some extra permissions though:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

But I don't see any red flags there..

I've tried the node remove option:

<manifest ...xmlns:tools="http://schemas.android.com/tools"...>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="remove" />

But nothing.

I've also run aapt2

$ aapt2 d permissions android/app/build/outputs/apk/myapp/release/app-myapp-release.apk
package: com.myapp
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.SYSTEM_ALERT_WINDOW'
uses-permission: name='com.android.vending.BILLING'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='android.permission.WAKE_LOCK'

Which doesn't tell me much more..

I've also watched the whole youtube video google posted regarding background positions, read the official docs, and checked every stack overflow post on this - but they just recommend the steps I've already taken.

It's an exhausting process! I'm exhausted. My best guess is that one our dependencies is the problem, but I have no good clues as to which one it could be.

Would really appreciate some fresh eyes.. maybe someones encountered this with one of these packages below and is just going to be like, that's the one! Delete it!

Otherwise it's back to desperate searching and brute force rebuilds on minimal information..

  "dependencies": {
    "@mapbox/geo-viewport": "0.4.1",
    "@mapbox/geojson-extent": "0.3.2",
    "@mapbox/polyline": "1.1.1",
    "@ptomasroos/react-native-multi-slider": "1.0.0",
    "@react-native-community/async-storage": "1.12.0",
    "@react-native-community/masked-view": "0.1.10",
    "@react-native-community/netinfo": "4.7.0",
    "@react-native-mapbox-gl/maps": "7.0.8",
    "@sentry/react-native": "1.8.2",
    "@turf/along": "^6.0.1",
    "@turf/bearing": "^6.0.1",
    "@turf/distance": "^6.0.1",
    "@turf/helpers": "^6.1.4",
    "@turf/line-distance": "^4.7.3",
    "@turf/nearest": "^4.7.3",
    "check-node-version": "4.0.3",
    "deprecated-react-native-listview": "^0.0.6",
    "eslint-plugin-react": "7.21.2",
    "install": "^0.13.0",
    "npm": "6.14.8",
    "prop-types": "^15.6.0",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-billing": "^3.0.0",
    "react-native-config": "^1.4.2",
    "react-native-elements": "^1.2.7",
    "react-native-gesture-handler": "1.8.0",
    "react-native-in-app-utils": "6.1.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-mixpanel": "1.2.5",
    "react-native-rate": "1.0.9",
    "react-native-safe-area-context": "^3.1.8",
    "react-native-screens": "2.8.0",
    "react-native-splash-screen": "3.2.0",
    "react-native-sqlite-2": "1.7.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webview": "10.9.3",
    "react-navigation": "4.0.10",
    "react-navigation-stack": "2.0.16",
    "url": "^0.11.0",
    "util": "0.12.3",
    "which-polygon": "2.2.0"
  },
  "devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-plugin-import": "2.22.1",
    "fs-extra": "^8.1.0",
    "jetifier": "1.6.6",
    "metro-react-native-babel-preset": "^0.58.0",
    "minimatch": "^3.0.4",
    "node-watch": "0.6.4",
    "rimraf": "2.7.1"
  }

Hopefully the right eyes sees this, or can point to something.. Thanks!

Update, got some more details from google:

Since your app does not need background location, please request to remove background usage and reach compliance:

If you are targeting Android 10 or newer (SDK level 29 or higher): Remove the ACCESS_BACKGROUND_LOCATION permission from your app APK or app bundle. If you’re using ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION, examine your code paths and restrict usage to foreground purposes only. (learn more: https://developer.android.com/training/location/background) You should no longer see the Location declaration listed in console under App Content. If your are targeting Android 9 or older (SDK level 28 or lower): If you’re already using ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION, examine your code paths and restrict usage to foreground purposes only. (learn more: https://developer.android.com/training/location/background) In your console declaration, select “No” to the question “Does your app access location in the background in APKs or app bundles targeting Android 9 or older?

6 Answers

I fixed this not by removing "ACCESS_BACKGROUND_LOCATION" from .js like grep -r "ACCESS_BACKGROUND_LOCATION" . | cut -c1-150 did, but by just removing "ACCESS_BACKGROUND_LOCATION" from .java like:

sed -i -e "s/.*ACCESS_BACKGROUND_LOCATION.*/return true;/g" node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java

Time will tell if this is an actual fix, but I figured I'd share it with other struggling devs.

Google approved both of our apps! 1 of our apps they approved because we just crumbled and told them we use background location, even though we don't. Not a satisfying answer!

The other app, I just cleared the build folder and resubmitted and they accepted it. So this points at the cache of the last uploader as the potential source of the problem. Though I am half expecting Google to take down the app in 2 weeks, we'll see.

Here's all my notes on clearing cache for devs who find themselves unsure if the cache is the root of the problem:

Clear cache inside project

rm android/build
rm ios/build
rm -rf android/.gradle
./gradlew clean

Clear cache inside computer

rm -rf ~/.gradle/caches

Other ios caches (For when you're really desperate)

~/Library/Caches/CocoaPods
~/Library/Developer/Xcode/DerivedData/*
~/Library/Developer/Xcode/Archives/*

Which of course brings to mind the old adage:

When in doubt – it's probably a caching issue.

I had this issue a few weeks ago, what a pain! In my case I had one dependency that was requiring background location without me noticing. Secondly, I had a wrong permission declaration on Google Play so my builds kept being rejected.

1. Find the evil dependency

To do this I used the Merged Manifest inspector in Android Studio. This shows you what your manifest looks like after all project dependencies have been taken into account. Find ACCESS_BACKGROUND_LOCATION and double click on it, this will bring you to the actual manifest where it's requested. Scroll to the top of this file and the package=some.package.name should help you identify what it is. In my case the permission was requested by an old dependency I didn't use anymore so I just uninstalled it.

Note: if you're often working on different branches, make sure you have the correct dependencies installed and make a clean build before checking the merged manifest:

cd android && yarn && ./gradlew clean && yarn android

2. Check Google Play declaration (optional)

Go to the Google Play Console. You can be sure the background location permission is removed from you app bundle by looking at the "Required permissions" in the App Bundle details. Then If you previously filled a background location permission declaration, make sure to review it and select No (your app may be removed from Google Play if it accesses location in the background). After that you should be good and you app should be approved promptly.

✌️

Note*
: Without filling delectation you can't upload your build so please first fill the declaration form on the play console and mention you are taking any background location access.

I have faced a similar kind in my release also, In the current build, I was not using any background location access. but In my previous build which was live in internal test on play console was using background location access. So due to that play console was halting me to upload any build for release before the declaration. Hence I have to solve the same problem with these steps.

1)Made a declaration app small video and mentioned that we are not using and background location access and posted it in the declaration form.

2)After this step I was able to publish so I have first uploaded my latest build to internal testing and released that.

  1. after a successful internal test release I published it to production.

As well as check alpha, beta test branch also on play console makes sure none of the previous app lives in these branches.

try looking for the permissions with the following command grep -r ACCESS_BACKGROUND_LOCATION android/* grep -r ACCESS_COARSE_LOCATION android/* etc ..

After that, if you already generated the app with bundleRelease, you will notice that the permissions are shown in the build folder.

just look for where the permissions are and see in that same file below which component uses it.

in my case it was the radar.io library.

Since you detect what library it is, it may be due to a component of react or some library that has to be removed from the gradle.

Update 5.21.2021: Welp, we just received a note from google that our apps have been taken down. So the solution below does not work, we just got caught up in the confusion and thought it was working.

Alright! We had a guy who fixed this. Here's how it was done.

  1. Manually delete ACCESS_BACKGROUND_LOCATION from any file anywhere in the react-native project, including node_modules, and bundles generated. Yeah I know, this sounds like a really silly thing, since they will come back next time you install, but we only have to get it approved once to get things working again.

Here's a command that'll work for that:

grep -r "ACCESS_BACKGROUND_LOCATION" . | cut -c1-150

You'll find files like these:

android/app/src/main/assets/index.android.bundle
node_modules/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js
node_modules/react-native/Libraries/PermissionsAndroid/NativePermissionsAndroid.js

Go through and delete "ACCESS_BACKGROUND_LOCATION"

  1. Then reupload the apk, and clear out any non-production tracks with the uploaded file, because they may have "ACCESS_BACKGROUND_LOCATION" in them.

After this, Google approved it..

The app never used background location, but at some point, someone may have indicated that it did use background location when uploading - Google remembered this, and that's why it took extra steps to get it approved I guess?

Not a very satisfying answer! Very hacky and uncertain.. Yet that's what worked for us. Now I will hope it never happens again.

Related