错误:包com.google.android.gcm不存在 - 迁移到Gradle后

fra*_*gon 6 android android-build google-play-services android-gradle-plugin

我在一个没有Gradle的IntelliJ中开发的旧项目有问题.我想将它迁移到Android Studio和Gradle,但我遇到了很多问题.由于该项目已经过时,因此使用了旧的Google Play服务版本.在Intellij中,我刚刚将旧gps的libproject添加到依赖项(google_play_services_5089000_r19),一切正常.在Android Studio中,我设法通过将其添加为库模块并添加compile project(':segmentedradios')为gradle依赖项来添加其他库,但我无法使gps库工作.我曾尝试将其添加为模块,但Android Studio在指向libroject库目录后表示"未选择模块" .我也尝试将其添加为gradle依赖项,但我不断遇到这样的错误:

error: package com.google.android.gcm does not exist
error: package com.google.android.maps does not exist
error: cannot find symbol variable GCMRegistrar
Run Code Online (Sandbox Code Playgroud)

尽管我尝试了10种不同的解决方案,但该项目仍然无效.怎么解决?

摇篮:

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'
}
Run Code Online (Sandbox Code Playgroud)

ian*_*ake 25

GCMRegistrar不属于Google Play服务,但属于现已完全弃用的 gcm.jar文件.

gcm.jar如果您希望暂时继续使用它,则需要添加到依赖项中,直到您迁移到Google Play Services的GCM实施:

compile files('libs/gcm.jar')
Run Code Online (Sandbox Code Playgroud)