在本机反应中需要类('com.google.android.gms.location.FusedLocationProviderClient'的声明)

问题描述 投票:0回答:4

这之前工作得很好。 可能的未处理的 Promise 拒绝(id:0): 错误:调用本机方法时遇到异常:在模块 ExpoLocation 上执行导出方法 getLastKnownPositionAsync 时发生异常:找到接口 com.google.android.gms.location.FusedLocationProviderClient,但需要类(声明“com.google.android.gms”) .location.FusedLocationProviderClient'

我已将以下内容添加到我的 build.gradle 文件中:

implementation 'com.google.android.gms:play-services-location:16.0.0'

package.json 文件:

{
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "appcenter": "4.4.5",
    "appcenter-analytics": "4.4.5",
    "appcenter-crashes": "4.4.5",
    "expo": "~41.0.1",
    "expo-location": "~12.0.4",
    "expo-splash-screen": "~0.10.2",
    "expo-status-bar": "~1.0.4",
    "expo-updates": "~0.5.4",
    "jwt-decode": "^2.2.0",
    "lottie-react-native": "^5.0.1",
    "radio-buttons-react-native": "^1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.4",
    "react-native-cli": "^2.0.1",
    "react-native-code-push": "^7.0.5",
    "react-native-elements": "^3.4.1",
    "react-native-fast-image": "^8.5.11",
    "react-native-geo-fencing": "^0.1.0",
    "react-native-geocoding": "^0.5.0",
    "react-native-geolocation-service": "^5.3.0-beta.3",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-google-places-autocomplete": "^2.2.0",
    "react-native-looped-carousel": "^0.1.13",
    "react-native-maps": "0.27.1",
    "react-native-push-notification": "^8.1.1",
    "react-native-razorpay": "^2.2.9",
    "react-native-reanimated": "^2.1.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "^3.1.1",
    "react-native-secure-storage": "^0.1.2",
    "react-native-share": "^7.2.1",
    "react-native-simple-toast": "^1.1.3",
    "react-native-svg": "^12.3.0",
    "react-native-unimodules": "~0.13.3",
    "react-native-version-check": "^3.4.3",
    "react-native-web": "~0.13.12",
    "react-native-webp-format": "^1.1.2",
    "react-navigation": "^4.4.4",
    "react-navigation-drawer": "^2.7.1",
    "react-navigation-stack": "^2.10.4",
    "react-navigation-tabs": "^2.11.2",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0"
  },
  "private": true,
  "name": "test",
  "version": "1.0.0"
}

android reactjs react-native expo native
4个回答
7
投票

此问题源于 Google Play 服务在最新版本中更新了一些内容。 https://developers.google.com/android/guides/releases#october_13_2022

我可以通过在

android/build.gradle
文件中将我的 google play 服务版本锁定为 20.0.0 来解决此问题。我们之前使用的是“+”。 See image here for the change


4
投票

正如 Christian Mitchell 所说,问题是由于 Google Play 服务最新版本造成的。解决方案是强制使用我们项目中使用的版本。

在项目 build.gradle 文件中添加 googlePlayServicesVersion = "17.+" 可能可以解决大多数人的问题,但就我而言这还不够。

使用 ./gradlew app:dependency 我注意到一个模块(react-native-activity-recognition)正在引用 gms,如下所示:api 'com.google.android.gms:play-services-location:+' 因此是最新的版本仍在全球使用

所以我的最终解决方案是在应用程序 build.gradle 中定位此模块并防止其嵌入 gms,如下所示:

implementation (project(path: ':react-native-activity-recognition')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
}

0
投票

您可以跟踪此链接,它只是 api 'com.google.android.gms:play-services-location:+' 错误,您将获得帮助https://github.com/Lyokone/flutterlocation/issues/802


0
投票

面临类似的问题,经过几个小时的调试,解决方案如下。

在 android/build.gradle 中:

在 buildscript.ext 中添加此行 =>

playServicesLocationVersion = "21.0.1"

在 android/app/build.gradle 中:

添加此行或将版本升级到 21.0.1(如果旧版本已存在)=>

implementation 'com.google.android.gms:play-services-location:21.0.1' **inside dependencies**
© www.soinside.com 2019 - 2024. All rights reserved.