begiNNer
begiNNer

Reputation: 138

Notification.setSound() isn't working with proguard

I have proguard problem which is including notification library. I can't hear notification sound if proguard is enabled. I couldn't find out which library was a problem.

app/build.gradle:

implementation 'com.google.android.gms:play-services-auth:16.0.1'

implementation 'com.google.android.gms:play-services-gcm:16.0.0'

implementation 'com.google.firebase:firebase-core:16.0.7'

implementation 'com.google.firebase:firebase-messaging:17.3.4'

implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'

implementation 'com.android.support:appcompat-v7:28.0.0'

implementation 'com.android.support:support-v13:28.0.0'

implementation 'com.android.support:design:28.0.0'

implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.android.support:cardview-v7:28.0.0'

My proguard:

# google gms
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents(); }
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL; }

-keep class com.google.android.gms.internal.** { *; }
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR; }

# fabric https://docs.fabric.io/android/crashlytics/dex-and-proguard.html
-keepattributes Signature
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

# android support
-keepnames class !android.support.v7.internal.view.menu.**, ** { *; }
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context); }
-keep public class * extends android.support.design.widget.CoordinatorLayout.Behavior { *; }
-keep public class * extends android.support.design.widget.ViewOffsetBehavior { *; }

Codes:

    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification);
    AudioAttributes attributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                   .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                    .build();

    // over android 8.0
    NotificationChannel mChannel = new NotificationChannel(Constants.MISSED_CALL, getString(R.string.notification), NotificationManager.IMPORTANCE_HIGH);

    mChannel.setSound(uri, attributes);
    getNotificationManager().createNotificationChannel(mChannel);

    // < 8.0
    android.app.Notification notification = builder
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setSound(uri)
                    .setStyle(setNotificationList(notificationList))
                    .build();

Upvotes: 0

Views: 636

Answers (1)

jspcal
jspcal

Reputation: 51904

Perhaps configure proguard to keep the notification related classes and the audio classes? Here's a partial example:

https://github.com/pusher/push-notifications-android/blob/master/pushnotifications/proguard-rules.pro

Upvotes: 1

Related Questions