0

In my app I have two product flavors. Both of them used to work fine. Suddenly I started to get ANR error when I try to run the application and the app freezes during start up. The error in Logcat is:

ANR in com.myapp.development PID: 7937 Reason: executing service com.myapp.development/com.myapp.development.service.MyFirebaseInstanceIDService

The method MyFirebaseInstanceIDService.onTokenRefresh is never called. The app freezes before any of my own code is executed.

The production flavor still works fine.

Everything in the Firebase console is set up correctly. The app is in the Play Store and both flavors used to work.

productFlavors {
        production {
            applicationId 'com.myapp'
            dimension "default"
        }
        development {
            applicationId 'com.myapp.development'
            dimension "default"
        }
    }

As you can see the only difference between the two flavors is the application id. And if I change the application id in the developmnet flavour it starts to work (the app does not freeze).

I tried the following tests:

  1. I change the package id of the development flavor by adding just one letter: 'com.myapp.developmentX'. I also make the corresponding change in google-services.json file . Then the development flavor also starts. But of course Firebase services do not work, because the new application id is not configured in Firebase console.
  2. In the manifest file I remove the MyFirebaseMessagingService and MyFirebaseMessagingService and MyFirebaseInstanceIDService. Then the app still freezes at start up, but the error in logcat changes slightly: ANR in com.myapp.development PID: 683 Reason: executing service com.myapp.development/com.google.firebase.iid.FirebaseInstanceIdService

  3. I checked out an old git branch and tried to start it but the problem is still there.

  4. I also tried: Uninstall the app and install again. Clean project. Delete the build directories. Restart the test device. Use the Android emulator. Restart the computer. Restart Android Studio. Update Android Studio to the latest 3.1.4 for Mac. But non of these helped.

It looks like the problem has something to do with the application id and Firebase, but I cannot find what. Anyone has any ideas?

Update after comments from Shark and sebasira.

In Firebase console I have one single project and there are two applications defined for it - one for each flavour. In that case there is no need of multiple google-services.json, one for each flavour. The file is the same for all flavours and can be places in the root directory : app/ google-services.json

The file structure is like that:

{
  "project_info": {...},
  "client": [...],
}

As you see, there is an array of clients. All application IDs (all flavours) are defined in that array. That's why if I download from Firebase the google-services.json file for each application, they are all the same.

Anyway, I tried to put a different google-services.json file for each flavor like that:

app/src/
    flavor1/google-services.json
    flavor2/google-services.json

But that didn't help.

hmitkov
  • 359
  • 4
  • 12

1 Answers1

1

I was facing exactly same issue, and my app configuration was also exactly similar as yours.

The issue was caused by the latest Facebook SDK I was using in my code, it crashes the Firebase before the app start hence the app goes to ANR.

I set my Facebook SDK version as 4.35.0 and that solved the issue.

Try it out and let me know if it was helpful.

  • Yes, setting the Facebook SDK to 4.35.0 solved the issue. Here is a related question: https://stackoverflow.com/questions/52113549/app-getting-stuck-with-e-com-facebook-internal-attributionidentifiers – hmitkov Sep 11 '18 at 13:48