Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to use the Google Calendar API for the first time in Android Studio, and this class is crashing once it gets to the

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

line.

The error say "Didn't find class "com.google.android.gms.auth.GoogleAuthUtil" on path: 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();
        }
    }
}
like image 817
S. Miller Avatar asked Feb 06 '23 18:02

S. Miller


1 Answers

I solved it.

Add the following in app build.gradle (Module:app)

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

Add the following in project build.gradle (Project:ProjectName)

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

Clean and Rebuild.

like image 173
Abhishek Balani Avatar answered Feb 27 '23 04:02

Abhishek Balani