Firebase-android-sdk: Crash in Android 8 and 9 after applying dexguard

Created on 4 Mar 2020  ·  6Comments  ·  Source: firebase/firebase-android-sdk

  • Android Studio version: Android Studio 3.6.1
  • Firebase Component: Firebase-messaging
  • Component version: 19.0.1

Crash in Android 8 and 9 in the background when sending push notification through firebase after applying dexguard obfuscation, same issue happen after updating the Firebase to 20.10

android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:363)
        at android.content.res.Resources.getString(Resources.java:456)
        at android.content.Context.getString(Context.java:580)
        at o.hc.ɩ(SourceFile:243)
        at o.he.ι(SourceFile:5007)
        at o.gW.ι(SourceFile:59)
        at o.fC.run(SourceFile:3002)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at o.ɬі.run(Unknown Source:6)
        at java.lang.Thread.run(Thread.java:764)

our firebase Messaging Service Implementation:
`public class ShahidFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = ShahidFirebaseMessagingService.class.getSimpleName();
public static final String KEY_URL = "url";

@Override
public void onNewToken(String registrationToken) {
    super.onNewToken(registrationToken);
    if (BuildConfig.DEBUG) {
        Log.d("TOKEN", "--->> " + registrationToken);
    }
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    // Check Remote Message
    if (remoteMessage == null) {
        Log.e(TAG, "RemoteMessage is null");
        return;
    }

    // Check Notification In RemoteMessage
    if (remoteMessage.getNotification() == null) {
        Log.e(TAG, "Notification is null");
        return;
    }
    String messageId = remoteMessage.getMessageId();
    RemoteMessage.Notification remoteMessageNotification = remoteMessage.getNotification();
    String title = remoteMessageNotification.getTitle();
    String content = remoteMessageNotification.getBody();
    if (TextUtils.isEmpty(content)) {
        Log.e(TAG, "Notification message content is null or empty");
        return;
    }
    Context context = getApplicationContext();
    Map<String, String> customDataMap = remoteMessage.getData();
    String deepLinkUrl = null;
    if (customDataMap != null && customDataMap.containsKey(KEY_URL)) {
        deepLinkUrl = customDataMap.get(KEY_URL);
    }
    Notification localNotification = NotificationHandler.getInstance(context).buildNotification(R.mipmap.ic_launcher, title, content, deepLinkUrl);
    // Using hash code since notification id is String by default
    NotificationHandler.getInstance(context).notify(Math.abs(messageId.hashCode()), localNotification);

}

}`

messaging

Most helpful comment

I found the problem.
Firebase load a string with name and not with R.string....
int var5 = var0.getResources().getIdentifier("fcm_fallback_notification_channel_label", "string", var0.getPackageName());
Then Dexguard remove this string.

With these two lines in the dexguard configuration you specify to keep the string above and all the strings that start with "fcm_"
-keepresources string/fcm_fallback_notification_channel_label
-keepresources string/fcm_*

All 6 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

I found the problem.
Firebase load a string with name and not with R.string....
int var5 = var0.getResources().getIdentifier("fcm_fallback_notification_channel_label", "string", var0.getPackageName());
Then Dexguard remove this string.

With these two lines in the dexguard configuration you specify to keep the string above and all the strings that start with "fcm_"
-keepresources string/fcm_fallback_notification_channel_label
-keepresources string/fcm_*

@TizioIncognito it's working Thank you!, but I think it should be handled inside the Firebase library so I will keep the issue open

Any plans to put this solution inside the library?

Same problem for me with DexGuard.
Thank you @TizioIncognito for the temporary workaround

Thanks for reporting.
Unfortunately, this is not a use case we can support since dexguard is not part of the default android toolchain unlike proguard.
Please report back if there are issues with proguard though.

Was this page helpful?
0 / 5 - 0 ratings