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

标签 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();
        }
    }
}

最佳答案

我解决了。

在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'
}

清理和重建。

关于android - 如何解决 "Didn' t find class 'com.google.android.gms.auth.GoogleAuthUtil'“错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37866058/

相关文章:

java - 如何在Android中创建 'Always on top overlay'

android - 有 Android Drawable 设计师吗?

android - 获取 Android 应用程序中的日历资源列表?

java - 谷歌日历 API。处理事件的共享扩展属性

android - 是否可以从 Android 应用程序创建新的谷歌日历?

android - ListView 项目未显示为已激活

android - 使双击在 WebView 中起作用

java - Firestore : (21. 4.1) [CustomClassMapper]:没有 setter /字段

ios - 有没有办法在 google 日历和 ios 日历中使用 URL 字段

google-calendar-api - Google Calendar API v3 在更新事件时返回 "Not Found"