Android Studio - GoogleAuthUtil cannot be resolved

霸气de小男生 提交于 2019-12-07 07:46:21

问题


I'm using Android Studio.

I need to use Google Accounts, but I'm getting an error.

Cannot resolve symbol 'GoogleAuthUtil'

I've imported the four main imports.

import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.GooglePlayServicesAvailabilityException;
import com.google.android.gms.auth.UserRecoverableAuthException;

Here's how I'm calling it.

final Account[] accounts = mAccountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);

My AndroidManifest.xml has the following.

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NETWORK" />

I selected Android 4.3 (Revision 18) Google APIs when starting my project.

Should I have the GooglePlayServices.jar in my libs folder? How do I do this in Android Studio?

I've tried restarting Android Studio, after trying to follow steps in this other question about Eclipse: GoogleAuthUtil cannot be resolved.


回答1:


This is a dup of a few other questions however:

Assure you have followed the documentation, make sure you have installed the Extras/Google Repository from the SDK Manager and added the following dependency to your <project>/<modulename>/build.gradle file (not the root .gradle file):

dependencies {
    compile 'com.google.android.gms:play-services-auth:16.0.+'
 }

Next sync your project and Gradle files using

then rebuild your project.


回答2:


You need to add play services auth to your build.gradle's dependencies like this: com.google.android.gms:play-services-auth:10.2.0

See more here: https://developers.google.com/android/guides/setup



来源:https://stackoverflow.com/questions/18114005/android-studio-googleauthutil-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!