'this permision (android.permission.QUERY_ALL_PACKAGES) was automatically added to Manifest

I have a react native app that it worked well until upgrade packages Actually after upgrade packages this permision added (android.permission.QUERY_ALL_PACKAGES) to manifest.please help me

this is first package.json

  {
  "name": "mazeapp",
  "version": "2.0.0",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@gregfrench/react-native-wheel-picker": "^1.2.15",
    "@miblanchard/react-native-slider": "^2.0.1",
    "@react-native-community/async-storage": "1.12.1",
    "@react-native-community/checkbox": "0.3.0",
    "@react-native-community/netinfo": "4.6.0",
    "@react-native-community/toolbar-android": "0.1.0-rc.2",
    "@react-native-firebase/app": "6.7.1",
    "@react-native-firebase/messaging": "6.7.1",
    "@react-native-picker/picker": "^1.9.10",
    "axios": "^0.19.0",
    "lottie-react-native": "3.5.0",
    "moment-jalaali": "^0.9.2",
    "react": "16.9.0",
    "react-dom": "16.9.0",
    "react-native": "0.61.5",
    "react-native-app-intro-slider": "4.0.4",
    "react-native-awesome-alerts": "1.4.2",
    "react-native-background-actions": "^2.6.4",
    "react-native-background-timer": "2.4.1",
    "react-native-check-box": "^2.1.7",
    "react-native-confirmation-code-field": "^4.1.0",
    "react-native-date-picker": "3.2.5",
    "react-native-device-info": "5.6.5",
    "react-native-easy-toast": "^1.2.0",
    "react-native-emoji": "1.8.0",
    "react-native-exit-app": "^1.1.0",
    "react-native-file-picker": "0.0.19",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "1.5.6",
    "react-native-i18n": "^2.0.15",
    "react-native-image-crop-picker": "^0.28.0",
    "react-native-image-picker": "2.3.4",
    "react-native-inappbrowser-reborn": "^3.5.1",
    "react-native-item-select": "0.3.0",
    "react-native-modal": "11.5.6",
    "react-native-modalbox": "2.0.2",
    "react-native-motion": "1.0.5",
    "react-native-otp-verify": "^1.0.3",
    "react-native-persian-calendar-picker": "^3.1.1",
    "react-native-popup-dialog": "0.18.3",
    "react-native-progress": "4.1.2",
    "react-native-push-notification": "^7.3.1",
    "react-native-rate": "^1.2.4",
    "react-native-ratings": "^7.4.0",
    "react-native-reanimated": "~1.4.0",
    "react-native-root-toast": "3.2.1",
    "react-native-safe-area-context": "0.6.0",
    "react-native-screens": "2.0.0-alpha.12",
    "react-native-sectioned-multi-select": "0.8.1",
    "react-native-select-contact": "^1.5.0",
    "react-native-simple-modal": "^9.0.1",
    "react-native-simple-radio-button": "^2.7.4",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "0.11.0",
    "react-native-sqlite-storage": "^5.0.0",
    "react-native-stars": "^1.2.2",
    "react-native-step-indicator": "^1.0.3",
    "react-native-svg": "9.13.3",
    "react-native-svg-charts": "5.4.0",
    "react-native-swiper": "^1.6.0",
    "react-native-table-component": "^1.2.1",
    "react-native-textinput-effects": "^0.5.1",
    "react-native-typing-animation": "^0.1.7",
    "react-native-uuid-generator": "^6.1.1",
    "react-native-vector-icons": "6.7.0",
    "react-native-view-more-text": "^2.1.0",
    "react-native-web": "^0.11.7",
    "react-native-webview": "^11.4.1",
    "react-navigation": "4.4.3",
    "react-navigation-stack": "^1.10.3",
    "react-navigation-tabs": "2.10.1",
    "react-number-format": "4.4.1",
    "react-redux": "7.2.2",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.12.0",
    "socket.io-client": "^2.4.0",
    "styled-components": "5.2.1",
    "victory-native": "^33.0.1"
  },
  "devDependencies": {
    "@babel/core": "7.12.3",
    "@babel/runtime": "7.12.1",
    "@react-native-community/eslint-config": "^0.0.7",
    "babel-jest": "25.5.1",
    "eslint": "^6.8.0",
    "jest": "25.5.4",
    "jetifier": "1.6.6",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-native-bundle-visualizer": "2.2.1",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

this is secound file package.json

 {
  "name": "mazeapp",
  "version": "2.1.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@miblanchard/react-native-slider": "^2.0.1",
    "@react-native-community/async-storage": "1.12.1",
    "@react-native-community/checkbox": "0.3.0",
    "@react-native-community/netinfo": "4.6.0",
    "@react-native-community/toolbar-android": "^0.2.1",
    "@react-native-firebase/analytics": "^14.0.0",
    "@react-native-firebase/app": "^14.0.0",
    "@react-native-firebase/messaging": "^14.0.0",
    "axios": "^0.19.0",
    "lottie-react-native": "3.5.0",
    "moment-jalaali": "^0.9.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-native": "^0.66.4",
    "react-native-app-intro-slider": "4.0.4",
    "react-native-awesome-alerts": "1.4.2",
    "react-native-background-actions": "^2.6.4",
    "react-native-background-timer": "2.4.1",
    "react-native-check-box": "^2.1.7",
    "react-native-confirmation-code-field": "^7.2.0",
    "react-native-device-info": "5.6.5",
    "react-native-emoji": "1.8.0",
    "react-native-exit-app": "^1.1.0",
    "react-native-file-picker": "0.0.19",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "1.5.6",
    "react-native-image-crop-picker": "^0.28.0",
    "react-native-image-picker": "2.3.4",
    "react-native-inappbrowser-reborn": "^3.5.1",
    "react-native-item-select": "0.3.0",
    "react-native-modal": "11.5.6",
    "react-native-modalbox": "2.0.2",
    "react-native-motion": "1.0.5",
    "react-native-otp-verify": "^1.0.3",
    "react-native-persian-calendar-picker": "^3.1.1",
    "react-native-progress": "4.1.2",
    "react-native-push-notification": "^7.3.1",
    "react-native-rate": "^1.2.4",
    "react-native-ratings": "^7.4.0",
    "react-native-reanimated": "~1.4.0",
    "react-native-root-toast": "^3.3.0",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "2.0.0-alpha.12",
    "react-native-select-contact": "^1.5.0",
    "react-native-simple-modal": "^9.0.1",
    "react-native-simple-radio-button": "^2.7.4",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "0.11.0",
    "react-native-sqlite-storage": "^5.0.0",
    "react-native-stars": "^1.2.2",
    "react-native-step-indicator": "^1.0.3",
    "react-native-svg": "^9.13.3",
    "react-native-svg-charts": "5.4.0",
    "react-native-swiper": "^1.6.0",
    "react-native-textinput-effects": "^0.5.1",
    "react-native-typing-animation": "^0.1.7",
    "react-native-uuid-generator": "^6.1.1",
    "react-native-vector-icons": "^9.0.0",
    "react-native-view-more-text": "^2.1.0",
    "react-native-web": "^0.11.7",
    "react-native-webview": "^11.4.1",
    "react-navigation": "4.4.3",
    "react-navigation-stack": "^1.10.3",
    "react-navigation-tabs": "^2.10.1",
    "react-number-format": "4.4.1",
    "react-redux": "7.2.2",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.12.0",
    "socket.io-client": "^2.4.0",
    "victory-native": "^33.0.1"
  },
  "devDependencies": {
    "@babel/core": "7.16.5",
    "@babel/runtime": "7.16.5",
    "@react-native-community/eslint-config": "2.0.0",
    "babel-jest": "26.6.3",
    "eslint": "7.14.0",
    "jest": "26.6.3",
    "jetifier": "1.6.6",
    "metro-react-native-babel-preset": "0.66.2",
    "react-native-bundle-visualizer": "2.2.1",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        // googlePlayServicesVersion = "4.3.3" // default: "+"
        // firebaseMessagingVersion = "+" // default: "+"
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
    }
}

allprojects {
    repositories {
        mavenCentral()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        google()
        maven { url 'https://jitpack.io' }
  
      }
}


Solution 1:[1]

It is because of target SDK updated to 30, some features (eg: Speech recognition,TTS) works in from android 11 device only after adding following code in our AndroidManifest.xml

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
        tools:node="remove" tools:ignore="QueryAllPackagesPermission" />

also android:exported="true" inside <activity>

It is mentioned in here Behavior changes: Apps targeting Android 11

Solution 2:[2]

For those having a similar issue or that have to explain to the Play Store why this permission is in place, this is added by react-native-inappbrowser-reborn package, there is a PR to fix that here:

https://github.com/proyecto26/react-native-inappbrowser/pull/335

It seems that at the time writing this post, it's not live in the NPM directory. But you should try to update the package and see if its gone.

One way to figure out which dependency injects permissions is by running this command at the root of your project (on unix based OS):

grep -r QUERY_ALL_PACKAGES *

This will tell you the file that has that text and this will point you on the right direction.

Solution 3:[3]

You can confirm that the package is included in your apk using.

apkTook

  1. install using instructions on website
  2. build your apk
  3. run apktool decode /path/to/your/app-release.apk
  4. There should now be a giant merged manifest file containing all permissions for your apk.

Once you have confirmed that the permission is included in your apk.

You can then use @imekinox 's answer to detect which dependency is including the permission.

You can then chose to disable the permission from appearing in your final APk file

by including the following change in your manifest.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.cortexmonitoring">


<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" tools:ignore="QueryAllPackagesPermission" />

Notice that xmlns:tools="http://schemas.android.com/tools" is required at the top of the manifest file.

More than likely the issue is https://github.com/proyecto26/react-native-inappbrowser/pull/335 and disabling the permission in this way may break this or other packages.

The real fix would be removing or updating any dependencies that include this permission.

Solution 4:[4]

for the ones who follow @Thanhal's answer:

check your AndroidManifest.xml file and add

xmlns:tools="http://schemas.android.com/tools"

to the manifest markup if it's not there.

example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
  package="your-app-package">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 imekinox
Solution 3 Sean Dunford
Solution 4