我有一个 React Native 应用程序,在我升级软件包之前一直运行良好。实际上,升级软件包后,此权限已添加到清单中:
android.permission.QUERY_ALL_PACKAGES
这是第一个
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"
}
}
这是第二个文件,
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' }
}
}
对于那些有类似问题或必须向 Play 商店解释为什么要设置此权限的人,这是由react-native-inappbrowser-reborn 包添加的,这里有一个 PR 可以解决这个问题:
https://github.com/proyecto26/react-native-inappbrowser/pull/335
在写这篇文章时,它似乎还没有存在于 NPM 目录中。但你应该尝试更新软件包,看看它是否消失了。
确定哪个依赖项注入权限的一种方法是在项目的根目录运行此命令(在基于 UNIX 的操作系统上):
grep -r QUERY_ALL_PACKAGES *
这将告诉您包含该文本的文件,并为您指明正确的方向。
这是因为目标 SDK 更新到 30,某些功能(例如:语音识别、TTS)只有在 AndroidManifest.xml 中添加以下代码后才能在 Android 11 设备上工作
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:node="remove" tools:ignore="QueryAllPackagesPermission" />
还有
android:exported="true"
里面<activity>
您可能必须在清单标头标记中专门声明工具命名空间才能使其工作。
xmlns:tools="http://schemas.android.com/tools"
这样标题就会像这样
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">
您可以使用以下命令确认该软件包是否包含在您的 apk 中。
apktool decode /path/to/your/app-release.apk
一旦您确认该权限已包含在您的 apk 中。
然后您可以使用 @imekinox 的 answer 来检测哪个依赖项包含该权限。
然后您可以选择禁用该权限出现在最终的 APk 文件中
在您的清单中包含以下更改。
<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" />
请注意,清单文件顶部需要
xmlns:tools="http://schemas.android.com/tools"
。
问题很可能是https://github.com/proyecto26/react-native-inappbrowser/pull/335,以这种方式禁用权限可能会破坏这个或其他包。
真正的修复方法是删除或更新包含此权限的任何依赖项。
对于关注@Thanhal答案的人:
检查您的 AndroidManifest.xml 文件并添加
xmlns:tools="http://schemas.android.com/tools"
到清单标记(如果不存在)。
示例:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your-app-package">
@imekinox 有正确的解决方案,但是,在我访问他链接的 Github 页面后,react-native-inappbrowser 的修复已合并,但尚未发布新版本。
我发现另一个 NPM 版本包含它: https://www.npmjs.com/package/@jinshin1013/react-native-inappbrowser-reborn
卸载旧版本并安装此版本,应该可以解决问题。
如果您使用 QUERY_ALL_PACKAGES 权限,您的应用很可能会被 Play 商店拒绝。
如下面的链接所述“在极少数情况下,元素无法提供足够的包可见性,您可以使用 QUERY_ALL_PACKAGES 权限。如果您在 Google Play 上发布您的应用,则您的应用使用此权限需要经过批准。”
https://developer.android.com/training/package-visibility
将查询添加到 AndroidManifest.xml 文件,如下所述。
<queries>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
<intent>
<action android:name="android.intent.action.GET_CONTENT" />
</intent>
</queries>