【问题标题】:Gradle setting problem with sending notification via firebase in Android studio在 Android Studio 中通过 Firebase 发送通知的 Gradle 设置问题
【发布时间】:2019-04-15 08:17:09
【问题描述】:

我尝试通过 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'

app 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;”

有人知道如何解决这个问题吗?非常感谢!

【问题讨论】:

  • 您解决了这个问题吗?我也有同样的问题。
  • 并非如此。相反,我降级了所有版本。

标签: android firebase parsing push-notification


【解决方案1】:

我也遇到过同样的问题,通过这个解决了

在你的 build.gradle (模块应用)

转到依赖项添加此代码

    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.19.0"

这将下载所需的文件
如果你遇到这个版本的问题,试试这个对我来说很好

    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.6"

来源 Github Project

【讨论】:

    猜你喜欢
    • 2020-12-24
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多