【问题标题】:error: package com.google.android.gcm does not exist - After migrating to Gradle错误:com.google.android.gcm 包不存在 - 迁移到 Gradle 后
【发布时间】:2015-03-09 22:25:54
【问题描述】:

我有一个在没有 Gradle 的情况下使用 IntelliJ 开发的旧项目的问题。我想将它迁移到 Android Studio 和 Gradle,但我遇到了很多问题。由于项目比较老,所以使用了旧的 Google Play Services 版本。在 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

尽管我尝试了大约 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'
}

【问题讨论】:

    标签: android android-gradle-plugin google-play-services android-build


    【解决方案1】:

    GCMRegistrar 不是 Google Play 服务的一部分,而是now entirely deprecated gcm.jar 文件的一部分。

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

    compile files('libs/gcm.jar')
    

    【讨论】:

    • 这是我从 Eclipse 切换到 AS 时唯一适用于我的应用程序的解决方案。
    • @mvreijn 我遇到了同样的问题,请问在哪里可以下载 gcm.jar 文件 *
    • @Rodrigo 我想我使用了这里介绍的解决方案:stackoverflow.com/a/28066114/1343553
    【解决方案2】:

    你可以通过这个路径下载gcm.jar

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

    或者这个

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

    下载后解压,扩展名应该是.jar而不是.jar.zip

    然后复制粘贴到你项目中的libs目录

    然后右击gcm.jar再点击add as lib

    就是这样

    【讨论】:

      【解决方案3】:

      您需要在应用程序的 build.gradle 文件中添加这两行:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-31
        • 2013-08-21
        • 1970-01-01
        • 1970-01-01
        • 2014-10-02
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多