我试图通过 Firebase 在我的 Android 应用程序中启用发送通知功能。按照教程,我在我的 AndroidManifest.xml 应用程序标记中添加了以下代码。
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:XXXXXX" />
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
我还在我的应用程序 build.gradle 文件的依赖项部分添加了以下代码:
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.5'
应用程序 build.gradle 文件如下所示:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
defaultConfig {
applicationId "edu.pitt.cs.mips.coursemirror"
minSdkVersion 19
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile files('libs/Parse-1.13.0.jar')
compile files('libs/ParseInterceptors-0.0.2.jar')
compile files('libs/android-pusher-0.6.jar')
compile files('libs/bolts-tasks-1.4.0-javadoc.jar')
compile files('libs/bolts-tasks-1.4.0.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/otto-1.3.4.jar')
compile files('libs/picasso-1.1.1.jar')
compile files('libs/retrofit-1.5.1.jar')
compile files('libs/volley.jar')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:27+'
compile 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.5'
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com/'
}
}
apply plugin: 'com.google.gms.google-services'
但是同步gradle后,AndroidManifest.xml中出现错误:
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
错误是:未解析的包“fcm”,以及未解析的类“ParseFirebaseMessagingService”和“ParseFirebaseInstanceIdService”。当我运行代码时,来自网站和应用程序内的推送通知功能都不起作用。 为了解决这个问题,我在 build.gradle 文件依赖部分包含了以下代码:
implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.5"
但是,与此更新同步后,在运行应用程序时,它会报告错误:“Multiple dex files define Lbolts/Task$UnobservedExceptionHandler;”
有人知道怎么解决这个问题吗?非常感谢!
最佳答案
我遇到过同样的问题并通过这个解决了
在你的build.gradle (module app)
转到依赖项添加此代码
implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.19.0"
这将下载所需的文件
如果你遇到这个版本的问题,试试这个对我来说很好用
implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.6"
关于android - 在 Android Studio 中通过 firebase 发送通知的 Gradle 设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53265063/