Google Play服务客户端出错

时间:2015-03-28 06:39:14

标签: android android-studio gradle

我一直在尝试让这个Android项目在带有gradle的android studio中运行。我对这一切都很陌生,所以这可能是一个简单的问题,但我已经花了很多天,并且无法克服我在尝试运行项目时收到的错误:

Error:(25, 62) error: package com.google.android.gms.common.GooglePlayServicesClient does not exist
Error:(26, 62) error: package com.google.android.gms.common.GooglePlayServicesClient does not exist
Error:(27, 39) error: cannot find symbol class LocationClient
Error:(42, 60) error: cannot find symbol class ConnectionCallbacks
Error:(43, 3) error: cannot find symbol class OnConnectionFailedListener
Error:(82, 10) error: cannot find symbol class LocationClient
Error:(586, 26) error: cannot find symbol class LocationClient
Error:(618, 2) error: method does not override or implement a method from a supertype
Error:(627, 2) error: method does not override or implement a method from a supertype
Error:(635, 2) error: method does not override or implement a method from a supertype

Error:Execution failed for task ':compileDebugJava'.
> Compilation failed; see the compiler error output for details.

以下是错误来自文件的顶部(我已标记有问题的行):

package edu.gatech.ppl.cycleatlanta;

import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.***GooglePlayServicesClient***.ConnectionCallbacks;
import com.google.android.gms.common.***GooglePlayServicesClient***.OnConnectionFailedListener;
import com.google.android.gms.***location.LocationClient***;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;

import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;

public class FragmentMainInput extends Fragment implements **ConnectionCallbacks**,
        **OnConnectionFailedListener**, LocationListener,
        OnMyLocationButtonClickListener {

    public static final String ARG_SECTION_NUMBER = "section_number";

    Intent fi;
    TripData trip;
    NoteData note;
    boolean isRecording = false;
    Timer timer;
    float curDistance;

    TextView txtDuration;
    TextView txtDistance;
    TextView txtCurSpeed;

    int zoomFlag = 1;

    Location currentLocation = new Location("");

    final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

    // Need handler for callbacks to the UI thread
    final Handler mHandler = new Handler();
    final Runnable mUpdateTimer = new Runnable() {
        public void run() {
            updateTimer();
        }
    };

    private final static int MENU_USER_INFO = 0;
    private final static int MENU_HELP = 1;

    private final static int CONTEXT_RETRY = 0;
    private final static int CONTEXT_DELETE = 1;

    DbAdapter mDb;
    GoogleMap map;
    UiSettings mUiSettings;
    private LocationClient mLocationClient;

    private static final LocationRequest REQUEST = LocationRequest.create()
            .setInterval(5000) // 5 seconds
            .setFastestInterval(16) // 16ms = 60fps
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    public FragmentMainInput() {
    }

当我悬停代码中标记的行时:

import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationClient;

它说:"无法解析符号"

这是我的build.gradle文件:

 buildscript {
            repositories {
                jcenter()
            }

            dependencies {
                classpath 'com.android.tools.build:gradle:1.1.0'

// NOTE: Do not place your application dependencies here; they
// belong in the individual module build.gradle files
            }
        }

allprojects {
    repositories {
        jcenter()
    }
}


apply plugin: 'com.android.application'

dependencies {

    compile 'com.android.support:appcompat-v7:22.0.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:7.0.0'
    compile files('libs/android-support-v4.jar')

}

android {
    compileSdkVersion 22
    buildToolsVersion "22"
    compileOptions.encoding = 'windows-1251'

    defaultConfig {

        minSdkVersion 19
        targetSdkVersion 22
        versionCode 2
        versionName "2.0"
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

这也是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="edu.gatech.ppl.cycleatlanta"
    android:versionCode="2"
    android:versionName="2.0" >

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="22" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" >
    </uses-feature>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
    </uses-permission>
    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.TabsConfig"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.MainInputActivity"
            android:label="@string/title_activity_main_input" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.TripPurposeActivity"
            android:label="@string/title_activity_trip_purpose" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.UserInfoActivity"
            android:label="@string/title_activity_user_info" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.TripMapActivity"
            android:label="@string/title_activity_trip_map" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.SavedTripsActivity"
            android:label="@string/title_activity_saved_trips" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.TripDetailActivity"
            android:label="@string/title_activity_trip_detail" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.NoteTypeActivity"
            android:label="@string/title_activity_note_type" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.NoteDetailActivity"
            android:label="@string/title_activity_note_detail" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.NoteMapActivity"
            android:label="@string/title_activity_note_map" >
        </activity>
        <activity
            android:name="edu.gatech.ppl.cycleatlanta.SavedNotesActivity"
            android:label="@string/title_activity_saved_notes" >
        </activity>

        <service
            android:name="edu.gatech.ppl.cycleatlanta.RecordingService"
            android:enabled="true"
            android:exported="true" >
        </service>

        <activity
            android:name="edu.gatech.ppl.cycleatlanta.MainActivity"
            android:label="@string/title_activity_main" >
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyB9orX8RcKrVvF8Vg1_yMhIvu59XUW_inw" />

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

在我看来谷歌播放服务链接存在问题。我已经关注了几个不同的例子并确实将其下载但我无法让它工作。另外我感觉我的清单(不确定sdk版本的正确目标)和gradle文件(jcenter或maven?并设置正确的依赖项)可能配置不正确。

任何有关这方面的帮助都会很棒我过去几天都在搜索互联网,但我无法解决我确定的简单问题...

3 个答案:

答案 0 :(得分:12)

如果您使用的是Google Play Services 7.0.0,则只需更改

即可
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;

import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;

如果你覆盖它,你也应该删除onDisconnected方法。

答案 1 :(得分:5)

您的位置实施基于较早版本的Google Play服务,但您导入了Play服务7.0.0&#34; GooglePlayServicesClient&#34;不再存在。

您可以在build.gradle文件中将播放服务版本更改为旧版本 要么 您可以使用this示例进行较新的位置实施。

答案 2 :(得分:3)

非常有趣,我继续潜伏着鼹鼠,并发现有人建议这个敌人在gradle构建中依赖:

    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.google.android.gms:play-services:4.+'
    compile 'com.android.support:cardview-v7:21.0.0'
    compile 'com.android.support:recyclerview-v7:21.0.0'

不确定是什么样的cardview或者回收者视图,但游戏服务是一个相当低的版本。但该死的东西建立了!现在唯一的问题是,只要您尝试打开它,应用程序就会在模拟器中崩溃(不幸的是它已经停止了消息)。我想知道这是一个新问题,还是我的配置还没有关闭?