如何解决 "Didn't find class 'com.google.android.gms.auth.GoogleAuthUtil'" 错误?

How can I resolve the "Didn't find class 'com.google.android.gms.auth.GoogleAuthUtil'" error?

我第一次尝试在 Android Studio 中使用 Google 日历 API,而这个 class 在到达

mService.events().insert("primary", event).execute();

行。

错误说 "Didn't find class "com.google.android.gms.auth.GoogleAuthUtil" 在路径上:DexPathList"


    public class CalendarRequestTask extends AsyncTask<Task, Void, Boolean> {
    private com.google.api.services.calendar.Calendar mService = null;
    private Exception mLastError = null;

    public CalendarRequestTask(GoogleAccountCredential credential) {
        HttpTransport transport = AndroidHttp.newCompatibleTransport();
        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
        mService = new com.google.api.services.calendar.Calendar.Builder(
                transport, jsonFactory, credential)
                .setApplicationName("Task Tracker")
                .build();
    }

    /**
     * Background task to call Google Calendar API.
     * @tasks has the date, title, summary of the event.
     */
    @Override
    protected Boolean doInBackground(Task... tasks) {
        try {
            setEventInApi(tasks);
            return true;
        } catch (Exception e) {
            mLastError = e;
            cancel(true);
            return false;
        }
    }

    private void setEventInApi(Task... tasks) throws IOException {
        // Insert an event into the Google Calendar

        for (Task task: tasks) {
            Event event = new Event()
                    .setSummary(task.getTitle())
                    .setDescription(task.getDescription());
            DateTime startTime = new DateTime(task.getDueDate());
            EventDateTime start = new EventDateTime()
                    .setDateTime(startTime);
            event.setStart(start);
            mService.events().insert("primary", event).execute();
        }
    }
}

我解决了。

在应用程序中添加以下内容 build.gradle (Module:app)

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

在项目build.gradle中添加以下内容(项目:项目名称)

dependencies {
classpath 'com.google.gms:google-services:1.5.0'
}

清理并重建。