我在应用程序中使用 ExpoLocation.startLocationUpdatesAsync 函数时遇到错误。错误信息是:
Caused by: rd.c: Initializing task consumer 'fd.b' failed. Inherited error: fd.b.<init> [class android.content.Context, interface fc.e]] code: 'ERR_UNEXPECTED'
此错误使我无法在后台捕获用户的位置。
对于熟悉位置服务以及在 Expo 或 React Native 中进行调试的程序员来说,这应该是清晰易懂的。
第 51 届世博会
package.json
"@expo/config-plugins": "~8.0.0",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/pro-light-svg-icons": "^6.5.2",
"@fortawesome/pro-regular-svg-icons": "^6.5.2",
"@fortawesome/pro-solid-svg-icons": "^6.5.2",
"@fortawesome/pro-thin-svg-icons": "^6.5.2",
"@fortawesome/react-native-fontawesome": "^0.3.2",
"@react-navigation/bottom-tabs": "^6.5.11",
"@react-navigation/drawer": "^6.6.6",
"@react-navigation/native": "^6.1.9",
"@react-navigation/stack": "^6.3.20",
"@react-navigation/tabs": "^0.0.0-alpha.12",
"axios": "^1.6.5",
"base-64": "^1.0.0",
"core-js": "^3.36.0",
"date-fns": "^3.3.1",
"expo": "~51.0.17",
"expo-asset": "~10.0.6",
"expo-barcode-scanner": "^13.0.1",
"expo-build-properties": "~0.12.3",
"expo-camera": "~15.0.12",
"expo-dev-client": "~4.0.19",
"expo-jwt": "^1.6.5",
"expo-location": "^17.0.1",
"expo-print": "~13.0.1",
"expo-router": "~3.5.17",
"expo-secure-store": "~13.0.2",
"expo-sharing": "~12.0.1",
"expo-sqlite": "~14.0.4",
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.6",
"expo-task-manager": "^11.8.2",
"jwt-decode": "^4.0.0",
"mobx": "^6.12.0",
"mobx-react-lite": "^4.0.5",
"native-base": "^3.4.28",
"react": "18.2.0",
"react-native": "0.74.2",
"react-native-gesture-handler": "~2.16.1",
"react-native-mask-input": "^1.2.3",
"react-native-modal": "^13.0.1",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "^4.10.1",
"react-native-signature-canvas": "^4.7.2",
"react-native-svg": "15.2.0",
"react-native-vector-icons": "^10.0.3",
"react-native-webview": "13.8.6"
app.json
"android": {
"permissions": [
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.FOREGROUND_SERVICE",
"android.permission.FOREGROUND_SERVICE_LOCATION",
"android.permission.ACCESS_BACKGROUND_LOCATION",
"android.permission.WAKE_LOCK",
"android.permission.CAMERA"
]
}
有一个错误,我需要捕获用户的位置。
我遇到了一个非常相似的错误。这可能是因为 Proguard 在幕后做了一些魔法。 (我假设你也启用了 Proguard。)我必须添加:
"plugins": [
[
"expo-build-properties",
{
"android": {
"compileSdkVersion": 34,
"targetSdkVersion": 34,
"buildToolsVersion": "34.0.0",
"usesCleartextTraffic": true,
"enableProguardInReleaseBuilds": true,
"enableShrinkResourcesInReleaseBuilds": true,
"extraProguardRules": "-keep class expo.modules.location.** { *; }" <-- This required
},
// Rest of config..
我认为你还可以添加规则列表;例如,
"extraProguardRules": ["-keep class expo.modules.location.** { *; }"]
但我没有测试过。
参考: