java - 无法将 Google Cloud Messaging 集成到 android 库模块中

标签 java android android-studio google-cloud-messaging

我能够将 GCM 集成到应用程序模块中,但无法集成到库模块中。我在应用程序模块中有这两行。

apply plugin: 'com.android.library'
apply plugin: 'com.google.gms.google-services'

我在 app 模块的依赖项中有这行代码。
compile 'com.google.android.gms:play-services-gcm:8.1.0'

这条线在项目顶层
classpath 'com.google.gms:google-services:1.4.0-beta3'

但是当我尝试通过扩展 GcmListenerService 来实现服务时,却无法检测到 GcmListenerService。

请提出建议,我尝试了 5 个多小时但无法解决问题。

最佳答案

首先,您通过将以下代码添加到应用程序 gradle 文件中,将 gcm jar 添加到您的项目中

ependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile files('libs/gcm.jar')
}

然后同步项目

关于java - 无法将 Google Cloud Messaging 集成到 android 库模块中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33125753/

相关文章:

java - v7 getSupportActionBar() 抛出 NullPointerException

android - 打开应用程序时,Android 会广播吗?

javascript - (React Native)当到达第一个数据集末尾时如何加载新数据并添加到组件(回收器 ListView )

尝试迁移 CSipSimple 时,Android Studio 无法解析符号实用程序

android - 在 Android Studio 中将 Google-Java-Client API 与 Google Contacts 包含在一起的最佳方式

java - Android Studio - 格式化我的笔记本后,谷歌地图 v2 无法工作

java - 如何在一个 TextView 中保留两个字符串的两种不同字体大小

java.lang.NumberFormatException : For input string: "2017-01-28 13:28:20" 异常

java - 如何解密X509证书签名

java - 从对象列表更新对象而不影响对象的原始引用