Error: com.google.android.gcm package does not exist - after switching to Gradle

I have a problem with an old project that was developed in IntelliJ without Gradle. I wanted to port it to Android Studio and Gradle, but I have a lot of problems. Since the project was quite old, the old version of Google Play Services was used. In Intellij, I just added the libproject of the old gps to the dependencies (google_play_services_5089000_r19) and everything worked fine. In Android Studio, I was able to add other libraries by adding them as a library module and adding compile project(':segmentedradios') as a gradle dependency, but I just can't do the work with the gps library. I tried to add it as a module, but Android Studio says that “no module is selected” after specifying the libroject library directory. I also tried adding it as a gradle dependency, but I keep getting errors like this:

 error: package com.google.android.gcm does not exist error: package com.google.android.maps does not exist error: cannot find symbol variable GCMRegistrar 

Despite the fact that I tried ~ 10 different solutions, the project still does not work. How to fix it?

Gradle:

 apply plugin: 'com.android.application' android { compileSdkVersion "Google Inc.:Google APIs:18" buildToolsVersion "21.1.2" defaultConfig { applicationId "my_package.app_name" minSdkVersion 14 targetSdkVersion 18 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile 'com.android.support:support-v4:18.0.0' compile files('libs/libGoogleAnalyticsV2.jar') compile project(':segmentedradios') compile 'com.google.android.gms:play-services:5.0.89' } 
+5
source share
3 answers

GCMRegistrar not part of the Google Play services, but is part of the now completely obsolete gcm.jar .

You need to add gcm.jar to your dependencies if you want to use it temporarily before moving on to the GCM implementation of Google Play Services:

 compile files('libs/gcm.jar') 
+22
source

You need to add both of these lines to the build.gradle file of your application:

 dependencies { ... compile 'com.google.maps:google-maps-services:0.1.3' compile 'com.google.android.gms:play-services:6.5.87' } 
+1
source

You can download gcm.jar along this path

http://www.java2s.com/Code/Jar/g/Downloadgcmjar.htm

or

http://www.java2s.com/Code/JarDownload/gcm/gcm.jar.zip

After downloading it, unzip it, it should have the extension .jar not .jar.zip

Then copy and paste it into libs dir in your project

Then right click on gcm.jar and select add as lib

It's him

0
source

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


All Articles