Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

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'
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...