什么是一个App Engine的后端的gradle必要依赖与谷歌云消息? [英] What are the necessary gradle dependencies for an App Engine Backend with Google Cloud Messaging?
问题描述
什么是一个App Engine后端与谷歌云消息?
必需依赖的gradle目前,当你添加一个模块,这样到Android Studio项目它增加了这种依赖性:
编译com.google.android.gms:发挥服务:8.4.0
但是,当您运行项目,你得到这个错误:
错误:执行失败的任务
':应用程序: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真
}但实际上并没有为我工作。
这样看来,我必须只指定GAE + GCM所需的库。到目前为止,我有:
编译com.google.android.gms:发挥服务-auth的:8.4.0
编译com.google.android.gms:播放服务-GCM:8.4.0
编译com.google.android.gms:播放服务基地:8.4.0完整列表这里。但是,这并不能正常工作。我得到这个错误:
E / GMPM:GoogleService初始化失败,状态:10,缺少的
预计资源:R.string.google_app_id初始化谷歌
服务。可能的原因是缺少谷歌,services.json或
com.google.gms.google服务插件的gradle
块引用>所以,我很茫然。
有没有解决这个问题,一些其他的方式?什么是奇怪的是我的老GAE + GCM项目做工精细导入整个谷歌播放服务。在我的新项目导入这些旧版本的谷歌播放服务不但是工作。所以,我不知道是怎么回事。
编辑:一些详细信息:
我做了一些测试。
1)开始新的Android Studio项目,增加了新的谷歌云模块'App Engine的Java的端点模块。自动生成的build.grade(模块:APP)是这样的:
{相关性
编译文件树(导演:'库',包括:['的* .jar'])
testCompile'的JUnit:JUnit的:4.12
编译com.android.support:appcompat-v7:23.1.1
编译com.android.support:design:23.1.1
编制项目(路径:':后端,配置:Android的终端)
}结果?编译和运行完美 - !没有问题
2)开始新的Android Studio项目,增加了新的谷歌云模块'App Engine的后端与谷歌云通讯。自动生成build.grade(模块:APP)是这样的:
{相关性
编译文件树(导演:'库',包括:['的* .jar'])
testCompile'的JUnit:JUnit的:4.12
编译com.android.support:appcompat-v7:23.1.1
编译com.android.support:design:23.1.1
编译com.google.android.gms:播放服务:8.4.0
编制项目(路径:':后端,配置:Android的终端)
}结果?同样糟糕的错误,我已经越来越!
所以它看起来像线编译com.google.android.gms:发挥服务:8.4.0''的问题。我用
取代了它编译com.google.android.gms:发挥服务-GCM:8.4.0''
因为理论上这是所有我需要谷歌的云消息。当我运行它,我得到这样的:
12-30 14:14:16.482 10573-10573 / com.myapp.myapp
E / GMPM:GoogleService初始化失败,状态:10,缺少的
预计资源:R.string.google_app_id初始化谷歌
服务。可能的原因是缺少谷歌,services.json或
com.google.gms.google服务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:是上传
不可能。应用测量禁用
块引用>所以看起来我缺少这个谷歌,services.json文件什么的。我不明白发生了什么事了Android工作室,因为几个月前,我做了一个GCM启用应用程序相同的方式,一个编译没有问题。该应用程序的gradle.build文件看起来是这样的:
{相关性
编译文件树(包括:['的* .jar'],DIR:库)
编制项目(路径:':GCM后端,配置:Android的终端)
编译com.android.support:appcompat-v7:22.2.0
编译com.ganyo:GCM服务器:1.0.2
编译com.google.android.gms:播放服务:7.5.0
编译com.android.support:support-v4:22.2.0
}因此,它看起来像Android的工作室停止添加编译com.ganyo:GCM服务器:1.0.2''的依赖。
于是我就一个项目
编译com.ganyo:GCM服务器:1.0.2
编译com.google.android.gms:播放服务:8.4.0结果?同一个执行失败的错误。
好了,所以让我们尝试在我的新项目老戏服务库:
编译com.ganyo:GCM服务器:1.0.2
编译com.google.android.gms:播放服务:7.5.0结果?同一个执行失败的错误。
我只是不明白为什么这是不工作的开箱像以前那样...
解决方案preliminary实验表明,该工程至今。
我把在看谷歌GCM示例项目在这里: HTTPS ://github.com/googlesamples/google-services/tree/master/android/gcm
和编辑的gradle我的文件。这里是他们的样子现在:
APP:
应用插件:'com.android.application安卓{
compileSdkVersion 23
buildToolsVersion23.0.2 defaultConfig {
的applicationIDcom.me.myapp
13的minSdkVersion
targetSdkVersion 23
版本code 1
的versionName1.0
}
buildTypes {
发布 {
minifyEnabled假
proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
}
}
}依赖{
编译文件树(导演:'库',包括:['的* .jar'])
编译com.google.android.gms:播放服务-GCM:8.4.0
testCompile'的JUnit:JUnit的:4.12
编制项目(路径:':后端,配置:Android的终端)
编译com.android.support:appcompat-v7:23.1.1
编译com.android.support:design:23.1.1
}应用插件:'com.google.gms.google的服务。项目:
//顶级构建文件,您可以添加常用的配置选项,所有分项目/模块。buildscript {
库{
jcenter()
}
依赖{
类路径'com.android.tools.build:gradle:1.5.0
类路径'com.google.gms:谷歌服务:2.0.0-素α3
//注意:不要在这里把你的应用程序依赖关系;他们属于
//在单个模块的build.gradle文件
}
}allprojects {
库{
jcenter()
}
}任务清除(类型:删除){
删除rootProject.buildDir
}和还我跟着这指南(见步骤2)生成我投进应用程序/目录谷歌-services.json文件。
现在应用程序编译和工作(至少到目前为止)。
我真的生气了,这并不开箱与自动生成的文件的gradle和我必须追捕他们在一些示例应用程序。它没有用是这样仅仅在几个月前。它一旦担任您添加的GCM模块。
如果任何人有任何提示/为将来的项目建议,请让我知道。 = D
What are the necessary gradle dependencies for an App Engine Backend with Google Cloud Messaging?
Currently, when you add a module like that to your Android Studio project it adds this dependency:
'compile 'com.google.android.gms:play-services:8.4.0'
However, when you run the project you get this error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Someone suggested using this:
defaultConfig { multiDexEnabled true }
But that actually didn't work for me.
So it appears that I have to specify only the required libraries for GAE + GCM. So far I have:
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'
full list here. But that didn't work. I got this error:
E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
So I am at a loss.
Is there some other way around this issue? What is weird is my old GAE + GCM projects work fine importing the whole google play services. Importing those older versions of google play services in my new project does not work however. So I am not sure what is going on.
EDIT: Some more information:
I did some tests.
1) Started new Android Studio project, added new google cloud module 'App Engine Java Endpoints Module'. The auto-generated build.grade (Module: app) looks like this:
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') }
Result? Compiles and runs perfectly - no problems!
2) Started new Android Studio project, added new google cloud module 'App Engine Backend with Google Cloud Messaging'. the auto-generated build.grade (Module: app) looks like this:
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') }
Result? Same crappy error I have been getting!
So it looks like the line 'compile 'com.google.android.gms:play-services:8.4.0'' is the problem. I replaced it with
'compile 'com.google.android.gms:play-services-gcm:8.4.0''
since in theory that is all I need for google cloud messaging. When I run it I get this:
12-30 14:14:16.482 10573-10573/com.myapp.myapp E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin. 12-30 14:14:16.482 10573-10573/com.myapp.myapp E/GMPM: Scheduler not set. Not logging error/warn. 12-30 14:14:16.502 10573-10623/com.myapp.myapp E/GMPM: Uploading is not possible. App measurement disabled
So it looks like I am missing this google-services.json file or something. I don't get what happened with Android Studio because several months ago I made a GCM enabled app the same way and that one compiles no problem. The gradle.build file of that app looks like this:
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' }
So it looks like Android Studio stopped adding the 'compile 'com.ganyo:gcm-server:1.0.2'' dependency.
So I ran a project with
'compile 'com.ganyo:gcm-server:1.0.2' 'compile 'com.google.android.gms:play-services:8.4.0'
Result? Same Execution failed error.
Ok so let's try the old play-services library in my new project:
'compile 'com.ganyo:gcm-server:1.0.2' 'compile 'com.google.android.gms:play-services:7.5.0'
Result? Same Execution failed error.
I just don't get why this isn't working out of the box like it used to...
解决方案Preliminary tests show that this works so far.
I took at a look at the google GCM sample project here: https://github.com/googlesamples/google-services/tree/master/android/gcm
And edited my gradle files. Here is what they look like now:
APP:
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.me.myapp" minSdkVersion 13 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.android.gms:play-services-gcm:8.4.0' testCompile 'junit:junit:4.12' compile project(path: ':backend', configuration: 'android-endpoints') compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' } apply plugin: 'com.google.gms.google-services'
PROJECT:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath 'com.google.gms:google-services:2.0.0-alpha3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
And also I followed this guide (see step 2) to generate a google-services.json file which I dropped into the app/ directory.
Now the app compiles and works (so far at least).
I'm really angry this doesn't work out of the box with the auto generated gradle files and that I have to hunt them down in some sample app. It didn't used to be this way just a few months ago. It worked as soon as you added the GCM module.
If anyone else has any tips/suggestions for future projects please let me know. =D
这篇关于什么是一个App Engine的后端的gradle必要依赖与谷歌云消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!