Android 导入导入 com.google.android.gms.common.AccountPicker 错误

Android import import com.google.android.gms.common.AccountPicker error

我正在尝试使用以下内容实现帐户选择器:

Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, false, null, null, null, null);

startActivityForResult(intent, 1111);

但我在导入时和 android 部分出现错误 导入 com.google.android.gms.common.AccountPicker

我该如何解决这个问题?

在构建中 Gradle 我有

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.0.1'

}

和这里的文章一样吗?

Exception java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker

您错过了将 GooglePlayService 添加到 build.gradlesetup 步骤。

在应用程序模块目录中的 build.gradle 文件中,在依赖项下为最新版本的播放服务添加新的构建规则:

compile 'com.google.android.gms:play-services:9.4.0'

如果你只需要AccountPicker:

1- 您可以将上面的行替换为:

compile 'com.google.android.gms:play-services-base:9.4.0'

因此您不需要编译完整的 gms,也不会面临 65,536 个方法的问题。

2- 您不需要添加google 播放服务来选择帐户。使用 AccountManager class.

中可用的 newChoosAccountIntent() 方法