无法调用 RNfusedlocation.getCurrentPosition -react-native-geolocation-service

Man*_*een 8 javascript reactjs react-native react-native-maps

调用 Geolocation.getCurrentPosition() 时,react-native-geolocation-service(^5.3.1) 会引发此错误或应用程序崩溃。添加react-native-maps(^1.8.0) 库后,错误开始出现。之前工作得很好。经过大量搜索后,我在某个地方看到这可能是由于其他模块的播放服务版本不匹配造成的。

反应本机版本 - 0.72.3

在我的 android/build.gradle > googlePlayServicesVersion = "17.0.0"

当我更改googlePlayServicesVersion版本时,构建失败并显示以下消息:`* 出了什么问题:无法确定任务':react-native-device-info:compileDebugAidl'的依赖关系。

无法解析配置“:react-native-device-info:debugCompileClasspath”的所有任务依赖项。找不到 com.google.android.gms:play-services-iid:18.0.0。需要者:项目:react-native-device-info

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。

BUILD FAILED in 9s 错误 无法安装应用程序。命令失败,退出代码 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 失败:构建失败并出现异常。* 出了什么问题:无法确定任务 ':react-native-device-info:compileDebugAidl' 的依赖关系。

无法解析配置“:react-native-device-info:debugCompileClasspath”的所有任务依赖项。> 找不到 com.google.android.gms:play-services-iid:18.0.0。需要者:项目:react-native-device-info`

尝试过 - 将 googlePlayServicesVersion 提高到 17.+/18.0.0/20.0.0。

implementation (project(path: ':react-native-device-info')) { exclude group: 'com.google.android.gms', module: 'play-services' } 在 android>app>build.gradle 中添加了上面的行

小智 27

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

在 android/build.gradle 中:

添加此行 =>playServicesLocationVersion = "21.0.1" 内部 buildscript.ext

在 android/app/build.gradle 中:

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

implementation 'com.google.android.gms:play-services-location:21.0.1' **inside dependencies**
Run Code Online (Sandbox Code Playgroud)


小智 6

试试这个=>

在 android/build.gradle 中:

buildscript {
ext {
    //..
    googlePlayServicesVersion = "21.0.1" //add this line
}
}
Run Code Online (Sandbox Code Playgroud)

在 android/app/build.gradle 中:

dependencies {
//..
implementation 'com.google.android.gms:play-services-location:21.0.1' // add this line

//..
Run Code Online (Sandbox Code Playgroud)

}