【问题标题】:Firebase Notification is not sent when minifyEnabled=true当 minifyEnabled=true 时不发送 Firebase 通知
【发布时间】:2022-01-22 15:52:46
【问题描述】:

我这几天一直有问题。我正在使用 Firebase Cloud Messaging 向我的 Android 应用发送通知。当 minifyEnabled=false 时,通知进入发布模式。但是,当 minifyEnabled=true 时,通知不会出现。我添加到 proguard-rules.pro 文件中的任何内容仍然没有出现。有什么想法吗?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.umit.app">

    <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name=".umitapp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"          
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <service
            android:name=".application.FirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        
        ...
        ..
        .

FirebaseMessagingService

class FirebaseMessagingService : FirebaseMessagingService() {
    
    override fun onNewToken(newToken: String) {
        super.onNewToken(newToken)
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        super.onMessageReceived(remoteMessage)
        App.sendNotification(remoteMessage)
    }       
}

proguardrules.pro

-keepattributes SourceFile,LineNumberTable
-keep class com.google.crypto.** { *; }
-keep class * extends com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite { *; }
-keep class com.google.googlesignin.** { *; }
-keepnames class com.google.googlesignin.* { *; }
-keep class com.google.android.gms.auth.** { *; }
-keep class com.google.gson.**{ *; }
-keep class androidx.renderscript.** { *; }
-keep class com.fivehundredpx.android.blur.BlurringView.** { *; }
-keepnames class androidx.navigation.fragment.NavHostFragment
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-repackageclasses ''
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
-keep class com.firebase.** { *; }
-keep class org.shaded.apache.** { *; }
-keepnames class com.shaded.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
-keepnames class com.firebase.** { *; }
-keepnames class com.shaded.fasterxml.jackson.** { *; }
-keepnames class org.shaded.apache.** { *; }
-keepnames class javax.servlet.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.commons.logging.impl.**
-keep class com.google.firebase.** { *; }
-keep class com.firebase.** { *; }
-keep class com.google.android.gms.** { *; }
-keep class android.support.v4.app.NotificationCompat { *; }
-keep class android.support.v4.app.NotificationCompat$* { *; }
-keep class android.support.v4.app.NotificationManagerCompat { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions
-dontwarn org.slf4j.**
-keep class com.transistorsoft.** { *; }
-dontwarn com.transistorsoft.**
-keep class ch.qos.** { *; }
-keep class org.slf4j.** { *; }
-dontwarn ch.qos.logback.core.net.*
-dontwarn okio.**
-keep class io.invertase.firebase.** { *; }
-dontwarn io.invertase.firebase.**
-keep class com.rt2zz.reactnativecontacts.** {*;}
-keepclassmembers class com.rt2zz.reactnativecontacts.** {*;}
-ignorewarnings
-keep class android.support.v4.app.NotificationCompat { *; }
-keep class android.support.v4.app.NotificationCompat$* { *; }
-keep class android.support.v4.app.NotificationManagerCompat { *; }
-keep class com.pusher.pushnotifications.** {
  *;
}
-keep class kotlin.Metadata { *; }
-keep, allowobfuscation public class * extends android.app.Activity
-keep, allowobfuscation public class * extends android.app.Application
-keep, allowobfuscation public class * extends android.app.Service
-keep, allowobfuscation public class * extends android.content.BroadcastReceiver
-keep, allowobfuscation public class * extends android.content.ContentProvider
-keep, allowobfuscation public class * extends android.app.backup.BackupAgentHelper
-keep, allowobfuscation public class * extends android.preference.Preference
-keep, allowobfuscation public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class **.R$* {
  public static <fields>;
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep public class * {
    public protected *;
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.examples.android.model.** { *; }
-dontwarn java.util.concurrent.Flow*
-keep class com.netmera.** { *; }
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.google.gson.examples.android.model.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
public *;
}
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep,allowshrinking class com.google.firebase.** { *; }
 -keep class com.microsoft.signalr.** { *; }
 -keep interface com.microsoft.signalr.** { *; }
 -keep public class androidx.preference.Preference {
     public <init>(android.content.Context, android.util.AttributeSet);
 }
 -keep public class * extends androidx.preference.Preference {
     public <init>(android.content.Context, android.util.AttributeSet);
 }
-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable

-keep public class android.app.NotificationChannel.** { *; }
-keep public class android.app.NotificationManager.** { *; }
-keep public class androidx.core.app.NotificationCompat.** { *; }
-keep public class androidx.core.content.ContextCompat.** { *; }
-keep public class com.google.firebase.messaging.FirebaseMessagingService.** { *; }
-keep public class com.google.firebase.messaging.RemoteMessage.** { *; }
-keep class com.google.firebase.messaging.RemoteMessage { *; }
-keep class com.umit.app.FirebaseMessagingService { *; }

【问题讨论】:

  • 请不要在收到答案后编辑问题,至少不要以使答案无效或(如在本例中)删除查找给定答案所需的信息的方式。您将回答者置于因“难以置信”或“胡乱猜测”的答案而被投反对票的风险。

标签: android firebase firebase-cloud-messaging proguard firebase-notifications


【解决方案1】:

如果您将 android sdk 定位到 android - 12,我们需要使用标志 mutable / or immutable 设置挂起的 Intent,并且我们还需要更新 firebase SDK。

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2018-11-13
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2016-03-16
      • 2019-01-30
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多