android - android studio firebase / 云消息传递
问题描述
每次我编译这两个错误都会出现。任何形式的帮助将不胜感激。
“实施‘com.google.firebase:firebase-messaging:17.3.1’”
“错误:com.google.android.gms.gcm 包不存在”
下面是我的 gradle 和 manifest 文件。
项目 Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用 Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.lrtapp.ardentmap"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.3.1'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:16.0.3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'me.biubiubiu.justifytext:library:1.1'
//Google Play Services
//implementation 'com.google.android.gms:play-services:11.4.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
}
apply plugin: 'com.google.gms.google-services'
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lrtapp.ardentmap">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/erlogo"
android:label="EaseRoute"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyALC_Pis5w391INiqcvnXO7dipxuMP0-JA" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MapActivity" />
<activity android:name=".About" />
<activity android:name=".Contact" />
<activity android:name=".Videos"></activity>
<service android:name=".FirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".MyFirebaseIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent"/>
</application>
</manifest>
提前感谢那些愿意提供帮助的人!!
解决方案
1)不确定您的错误是什么,但您的 Firebase 依赖项必须是相同的版本。您正在使用 17.3.1 进行 firebase-messaging,但您的 firebase-core 是 16.0.3。
2)您尚未在 gradle 中添加 GCM 依赖项:
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
但最重要的是,为什么要在同一个应用程序中实现 firebase 消息传递和 GCM?Google 强烈建议您不要这样做。此外,GCM 将于 2019 年 4 月关闭。
推荐阅读
- python - Python:重采样和前向填充到最近一个月
- graph - 如何将表格导出为 png 文件?
- python - 无法从 JWT 导入 TokenObtainPairView、TokenRefreshView
- javascript - 如何让 Chrome 扩展程序休眠一段时间并在端口上发布消息
- python - 优化大型excel文件的处理
- javascript - 如何使用javascript为每个表行打印不同的值
- ide - Liferay Cloud IDE,多个开发人员在同一个 liferay 服务器上工作
- php - Laravel 将退出状态代码任意设置为自定义命令
- ios - 旋转图像后缺少缩放
- sql-server - 计算日期范围内的星期六数 - SQL