首页 > 解决方案 > 在android中“minifyEnabled true”后未收到通知,为什么?

问题描述

我的通知在 build.gradel 文件 minifyEnabled false时收到,但每当我们更改minifyEnabled true时,我的签名版本 APK 中未收到通知。这是我的build.gradel文件,

android {
    compileSdkVersion 28
defaultConfig {
    applicationId "com.abc.xyz.test"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 10
    versionName "1.0.8"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    signingConfig signingConfigs.brand_champs
}
lintOptions {
    disable 'GoogleAppIndexingWarning'
    warningsAsErrors true
    checkReleaseBuilds false
}
dexOptions {
    javaMaxHeapSize "4g"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
 'proguard-rules.pro'
        debuggable false
        jniDebuggable false
        renderscriptDebuggable false
        zipAlignEnabled false
    }
    debug {
        debuggable true
        zipAlignEnabled false
        jniDebuggable false
        minifyEnabled false
    }
 }

}

标签: androidpush-notificationfirebase-cloud-messagingandroid-notifications

解决方案


朋友解决了以上问题,

此问题与启用 proguard 时从代码中删除的类迁移或未使用的类有关。

我们在proguard文件中写了保留规则,并保留了与通知相关的应用程序的我的所有模型

-keepclassmembers class com.xyz.test.model.** {
 *;
}

这是我的类模型“com.xyz.test.model.**”,你有任何不同的类,根据你的 id 和包名


推荐阅读