如何解决“未找到课程'com.google.android.gms.auth.GoogleAuthUtil'”错误?

时间:2016-06-16 17:45:08

标签: android google-calendar-api

我试图在Android Studio中首次使用Google Calendar API,这个类一旦到达

就崩溃了
mService.events().insert("primary", event).execute();

线。

错误说 “未在路径上找到”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();
        }
    }
}

1 个答案:

答案 0 :(得分:7)

我解决了。

在app build.gradle(Module:app)

中添加以下内容
dependencies{
..
compile 'com.google.android.gms:play-services-auth:9.0.2'
}

在项目build.gradle(Project:ProjectName)

中添加以下内容
dependencies {
classpath 'com.google.gms:google-services:1.5.0'
}

清洁和重建。