使用 Google Cloud Messaging 的 App Engine 后端有哪些必要的 gradle 依赖项?
目前,当您将类似的模块添加到 Android Studio 项目时,它会添加以下依赖项:
'编译'com.google.android.gms:play-services:8.4.0'
但是,当您运行该项目时,您会收到此错误:
错误:任务执行失败
':app:transformClassesWithDexForDebug'。
com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:处理'命令
'/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java''
以非零退出值 2 完成
有人建议使用这个:
defaultConfig {
multiDexEnabled true
}
但这实际上对我不起作用。
所以看来我必须只指定 GAE + GCM 所需的库。到目前为止我有:
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
完整列表在这里 https://developers.google.com/android/guides/setup。但这没有用。我收到这个错误:
E/GMPM:GoogleService 初始化失败,状态:10,缺少
预期资源:'R.string.google_app_id' 用于初始化 Google
服务。可能的原因是缺少 google-services.json 或
com.google.gms.google-services gradle 插件。
所以我很茫然。
还有其他方法可以解决这个问题吗?奇怪的是我的旧 GAE + GCM 项目在导入整个 google play 服务时运行良好。然而,在我的新项目中导入旧版本的 Google Play 服务不起作用。所以我不确定发生了什么事。
编辑:更多信息:
我做了一些测试。
1)开始新的Android Studio项目,添加新的谷歌云模块“App Engine Java Endpoints Module”。自动生成的 build.grade (模块:app)如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(path: ':backend', configuration: 'android-endpoints')
}
结果?编译并运行完美 - 没有问题!
2)开始新的Android Studio项目,添加新的谷歌云模块“App Engine Backend with Google Cloud Messaging”。自动生成的 build.grade (模块:app)如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
结果?我也遇到过同样的糟糕错误!
所以看起来“compile 'com.google.android.gms:play-services:8.4.0”行就是问题所在。我把它替换为
'编译'com.google.android.gms:play-services-gcm:8.4.0''
因为从理论上讲,这就是我对谷歌云消息传递所需要的全部。当我运行它时,我得到这个:
12-30 14:14:16.482 10573-10573/com.myapp.myapp
E/GMPM:GoogleService 初始化失败,状态:10,缺少
预期资源:'R.string.google_app_id' 用于初始化 Google
服务。可能的原因是缺少 google-services.json 或
com.google.gms.google-services gradle 插件。 12-30 14:14:16.482
10573-10573/com.myapp.myapp E/GMPM:调度程序不
放。不记录错误/警告。 12-30 14:14:16.502
10573-10623/com.myapp.myapp E/GMPM:正在上传
不可能。应用程序测量已禁用
所以看起来我缺少这个 google-services.json 文件或其他东西。我不明白 Android Studio 发生了什么,因为几个月前我用同样的方式制作了一个支持 GCM 的应用程序,并且编译没有问题。该应用程序的 gradle.build 文件如下所示:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(path: ':gcm-backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.ganyo:gcm-server:1.0.2'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:support-v4:22.2.0'
}
所以看起来 Android Studio 停止添加“compile 'com.ganyo:gcm-server:1.0.2”依赖项。
所以我运行了一个项目
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:8.4.0'
结果?相同的执行失败错误。
好吧,让我们在我的新项目中尝试旧的播放服务库:
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:7.5.0'
结果?相同的执行失败错误。
我只是不明白为什么这不能像以前那样开箱即用......