当 minifyEnabled=true 时,不会发送 Firebase 通知

问题描述 投票:0回答:3

我这几天一直遇到问题。我正在使用 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>
        
        ...
        ..
        .

Firebase 消息服务

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
3个回答
1
投票

如果您的目标 android sdk 为 android - 12,我们需要使用 Flag 可变/或不可变设置挂起意图,并且我们还需要更新 firebase SDK。



0
投票

将此行规则添加到 Gradle 脚本中的

Proguard-rules

-keep class com.google.api.** { *; }
© www.soinside.com 2019 - 2024. All rights reserved.