Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: package com.google.android.gcm does not exist - After migrating to Gradle

I have a problem with an old project which was developed in IntelliJ without Gradle. I wanted to migrate it to Android Studio and Gradle, but I am experiencing a lot of problems. Since the project was quite old, the old Google Play Services version was used. In Intellij I had just added libproject of the old gps to dependencies (google_play_services_5089000_r19) and everything worked fine. In Android Studio I managed to add other libraries by adding it as a library module and adding compile project(':segmentedradios') as a gradle dependency, but I just can't make gps library work. I've tried to add it as a module, but Android Studio says that "no module selected" after pointing to libroject library's directory. I also tried to add it as a gradle dependency, but I am keep getting errors like these:

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 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'
}
like image 723
fragon Avatar asked Mar 09 '15 22:03

fragon


3 Answers

GCMRegistrar is not part of Google Play Services, but is part of the now entirely deprecated gcm.jar file.

You'll need to add gcm.jar to your dependencies if you'd like to temporarily keep using it until you migrate to Google Play Services' GCM implementation:

compile files('libs/gcm.jar')
like image 113
ianhanniballake Avatar answered Oct 20 '22 02:10

ianhanniballake


You can download gcm.jar by this path

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

or this

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

After you download it, unzip it, it should have extention .jar not .jar.zip

Then copy and paste it to libs dir in your project

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

That is it

like image 2
Aleksey Timoshchenko Avatar answered Oct 20 '22 03:10

Aleksey Timoshchenko


You need to add these both lines in your 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'
}
like image 1
Guillaume agis Avatar answered Oct 20 '22 02:10

Guillaume agis