What are the required gradle dependencies for the Google Cloud Messaging App Engine firewall?

What are the required gradle dependencies for the Google Cloud Messaging App Engine firewall?

Currently, when you add such a module to your Android Studio project, it adds this dependency:

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

However, when you start the project, you get this error:

Error: execution completed for task ': Application: 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 '"completed with nonzero exit value 2

Someone suggested using this:

defaultConfig { multiDexEnabled true } 

But that really didn't work for me.

So, it seems that I should specify only the necessary libraries for GAE + GCM. So far, I:

 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 did not work. I got this error:

E / GMPM: GoogleService failed to initialize, status: 10, Missing expected resource: "R.string.google_app_id" to initialize Google Services. Possible reasons are missing google-services.json or com.google.gms.google-services gradle.

Therefore, I find it difficult.

Is there any other way to solve this problem? It’s strange that my old GAE + GCM projects work perfectly with all Google Play services. However, importing old versions of Google Play services in my new project does not work. Therefore, I am not sure what is going on.

EDIT: Additional Information:

I did some tests.

1) Launched a new project for Android Studio, a new Google App Engine Java Endpoints Module cloud module was added. The build.grade generator (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 works fine - no problem!

2) Started a new Android Studio project, added a new Google App Engine cloud module using Google Cloud Messaging. automatically generated build.grade (Module: app) is as follows:

 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? I also crappy mistake that I get!

So it looks like the command line "compile" com.google.android.gms: play-services: 8.4.0 ''. I replaced it with

'compile' com.google.android.gms: play-services-gcm: 8.4.0 ''

since in theory that’s all I need for Google cloud messaging. When I run it, I get the following:

12-30 14: 14: 16.482 10573-10573 / com.myapp.myapp E / GMPM: GoogleService failed to initialize, status: 10, Missing expected resource: "R.string.google_app_id" to initialize Google Services. Possible reasons are missing google-services.json or com.google.gms.google-services gradle. 12-30 14: 14: 16,482 10573-10573 / com.myapp.myapp E / GMPM: Do not set the scheduler. Do not log error / warning. 12-30 14: 14: 16,502 10573-10623 / com.myapp.myapp E / GMPM: download not possible. Failed to install the application.

So it looks like I'm missing this google-services.json file or something like that. I don’t understand what happened with Android Studio, because a few months ago I made an application with GCM turned on in the same way and no one compiles any problems. The gradle.build file of this application is as follows:

 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 has stopped adding the “compile” com.ganyo: gcm-server: 1.0.2 '' dependency.

So, I started the project with

 'compile 'com.ganyo:gcm-server:1.0.2' 'compile 'com.google.android.gms:play-services:8.4.0' 

Result? Error with the same execution.

So, try the old game 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? Error with the same execution.

I just do not understand why this does not work out of the box, as before ...

+4
source share
3 answers

So, this should be regarded as a problem with Android Studio, since simply adding the “App Engine Interface with Google Cloud Messaging” module will break the assembly into the simplest applications every time due to its complete dependence on Google Play Services, com.google.android .gms: play-services: 8.4.0 ', large enough to exceed the 65K DEX limit. This problem is actually documented in the "Configuring Google Play Services" section.

The solution, as you discovered, will manually edit your build.gradle and add only imports for GCM 'com.google.android.gms: play-services-gcm: 8.4.0'. The requirement for "google-services.json", which will be added manually, is normal, though, since you need to generate it for your project on developers.google.com. Adding "multiDexEnabled true" is not a good solution, as it increases the size of the APK unnecessarily, and you still get duplicate dependencies.

I created an entry in the Android Problem Tracker to fix dependencies for the GCM server's BackMod module in Android Studio. Feel free to ask this issue for visibility and updates.

+3
source

Preliminary tests show that this still works.

I reviewed here an example of a Google GCM project: https://github.com/googlesamples/google-services/tree/master/android/gcm

And edited my gradle files. Here's 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 } 

I also completed this guide (see step 2) to create the google-services.json file, which I put in the app / directory.

Now the application compiles and works (at least for now).

I am very angry that this does not work out of the box with automatically generated gradle files and that I should look for them in some sample application. This was not so, just a few months ago. It worked as soon as you added the GCM module.

If anyone has any tips / suggestions for future projects, please let me know. = D

+1
source

If you get to the scene where you need to start with MultiDex turned on, you need to complete three steps:

  • Include it in your defaultConfig in Gradle, as you already tried:

     defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } 
  • Include it in your dependencies:

     dependencies { compile 'com.android.support:multidex:1.0.0' } 
  • Add it to your manifest:

     <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application> </manifest> 

https://developer.android.com/intl/es/tools/building/multidex.html#about

But always be well versed in the dependencies that you already have, since this is usually not required.

0
source

Source: https://habr.com/ru/post/1237349/


All Articles