【问题标题】:Can't find the class com.google.android.gms.location.LocationClient (android)找不到类 com.google.android.gms.location.LocationClient (android)
【发布时间】:2013-05-14 05:32:18
【问题描述】:

我已经从http://developer.android.com/training/location/retrieve-current.html下载了一个演示项目,我想我没有丢失任何步骤;但我找不到哪个 jar 文件包含“com.google.android.gms.location.LocationClient.class”文件

我们找到了所有“google-play-services.jar”和“maps.jar”,以及“android.jar(所有版本)” 不包含“LocationClient.class”?

【问题讨论】:

  • 我只是通过“Android SDK Manager”更新“extras\google play service”,我发现最新的“google-play-services.jar”包含“LocationClient.class”文件; (以及 5 天前刚刚下载的旧“google-play-services.jar”文件)

标签: android location


【解决方案1】:

添加到 Gradle 文件(x.y.z - Google Play 服务的实际版本):

compile 'com.google.android.gms:play-services-location:x.y.z'

【讨论】:

  • 目前最新的是:compile 'com.google.android.gms:play-services-location:8.4.0'
【解决方案2】:

最后一个 GPS 库有问题。您必须使用比最新版本(6.+)更旧的版本。尝试使用旧版本。我没有看到文档中关于LocationClient.class 的任何内容被弃用或丢失。

compile 'com.google.android.gms:play-services:5.+'

【讨论】:

【解决方案3】:

LocationClient 已弃用。你必须使用GoogleApiclient,像这样:

1:声明一个 GoogleApiClient 变量

private GoogleApiClient mGoogleApiClient;

2:实例化

mGoogleApiClient = new GoogleApiClient.Builder(mThisActivity)
     .addApi(LocationServices.API)
     .addConnectionCallbacks(this)
     .addOnConnectionFailedListener(this)
     .build();

3:实现回调

public class YourClass extends BaseFragment implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener, LocationListener {

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // your code goes here
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        //your code goes here
    }

    @Override
    public void onConnectionSuspended(int cause) {
        //your code goes here       
    }
}

4:开始获取位置更新:

LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

5:删除位置更新:

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

6:获取最后已知位置:

private Location mCurrentLocation;

mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

【讨论】:

  • 谢谢,这是我用这个新 API 重写我的位置助手类的好方法。
【解决方案4】:

由于 Location Client 已被弃用,因此该类不再在包中找到。我们必须改用以下内容

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks(){

    @Override
    public void onConnected(Bundle arg0) {
        // TODO Auto-generated method stub
        LocationRequest request = new LocationRequest();
        int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
        if (enableHighAccuracy) {
          priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
        }
        request.setPriority(priority);

        LocationServices.FusedLocationApi.requestLocationUpdates(
                locationClient, request, new LocationListener() {

                  @Override
                  public void onLocationChanged(Location location) {

                    locationClient.disconnect();
                  }

        });
    }

    @Override
    public void onConnectionSuspended(int arg0) {
        // TODO Auto-generated method stub

    }
    })
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        // TODO Auto-generated method stub

    }
})
.build();

【讨论】:

    【解决方案5】:

    Jeremie Petitjean 的解决方案对我有用。进入youbuild.grade 文件并将您的应用程序配置为较低版本。这是我使用的,现在可以使用:

    apply plugin: 'com.android.application'   
    android {
        compileSdkVersion 19
        buildToolsVersion "19.1.0"
    
    defaultConfig {
        applicationId "<APPLICATION NAME>"
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:19.1.0'
        compile 'com.android.support:appcompat-v7:19.0.1'
        compile 'com.google.android.gms:play-services:4.2+'
    }
    

    【讨论】:

      【解决方案6】:

      您需要更新 Google Play Service SDK,然后使用更新的库。

      【讨论】:

        【解决方案7】:

        为了直接使用 Phonegap CLI 的任何人的利益。在您的 plugin.xml 中,您需要该行

        <framework src="com.google.android.gms:play-services-location:+" />
        

        【讨论】:

          【解决方案8】:

          查看以下链接

          The import com.google.android.gms cannot be resolved

          How to add google-play-services.jar project dependency so my project will run and present map

          按照这些步骤操作并节省您的时间

          1. 右键单击您的项目资源管理器。
          2. 从现有代码中选择新建-> 项目-> Android 应用程序项目
          3. 仅浏览至此路径 - “C:\Users\用户名\Local\Android\sdk\extras\google\google_play_services”
          4. 小心只浏览 - google_play_services 而不是 google_play_services_lib

          这样您就可以导入 google play 服务库。 如果您对此有任何疑问,请告诉我。

          【讨论】:

            【解决方案9】:

            如果你使用 Android Studio,试试这个:

            右键单击您的应用文件夹->打开模块设置->依赖项->单击加号按钮->选择库依赖项->搜索“play-services”->双击com.google.android。 gms:播放服务

            按确定并等待 Gradle 重建。如果发生错误,请清理并重建您的项目。 here

            【讨论】:

              【解决方案10】:

              将此添加到您的项目中`

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

              【讨论】:

                【解决方案11】:

                使用 Android SDK 管理器将 Google Play 库更新到最新版本。此外,我必须手动删除该库并在these steps 之后将其再次添加到我的项目中。 3.1.36 版包含:

                位置文件夹:

                您可能还需要更新 ADT/SDK。

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2015-04-13
                  • 2014-04-21
                  • 2014-08-19
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多