为什么我无法导入com.google.android.gms.location.LocationListener;和LocationRequest,还有LocationServices?

Gil*_*han -1 java android location google-maps

我正在尝试使用使用直接用户位置的android studio构建一个android应用,并且在导入com.google.android.gms.location.LocationListener时出现错误;它说它无法解析符号“ LocationListener”,对于“ LocationRequest”和“ LocationServices”,我也尝试搜索答案,但我无法弄清楚问题出在哪里。

not*_*bit 7

自 2018 年 Gradle 3.0.0 以来,情况发生了变化。现在您必须 在 , 部分中使用:implementation而不是, 。像这样:compile./app/build.gradledependencies{}

dependencies {
    ...
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    ...
}
Run Code Online (Sandbox Code Playgroud)

location发布网页中搜索。


Rak*_*sal 6

尝试添加以下内容:

   compile 'com.google.android.gms:play-services:9.8.0' 
Run Code Online (Sandbox Code Playgroud)

在您的应用程序级别gradle依赖项中

 classpath 'com.google.gms:google-services:3.1.0'
Run Code Online (Sandbox Code Playgroud)

在项目级别的gradle依赖项中

请注意,版本可能会根据您的SDK配置或您的偏好而更改