Firebase Remoteconfig fetch crashes Android app

3k views Asked by At

As in the title. Fetching Firebase config crashes the app. In the same application Firebase database and crash reporting works perfectly.

Error messsage:

Caused by: java.lang.IllegalStateException: Activity has been destroyed
                  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1854)
                  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:643)
                  at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:608)
                  at com.google.android.gms.internal.zzrn.zza(Unknown Source)
                  at com.google.android.gms.internal.zzra.zzc(Unknown Source)
                  at com.google.android.gms.internal.zzra.zzs(Unknown Source)
                  at com.google.android.gms.tasks.zzh$zza.zzv(Unknown Source)
                  at com.google.android.gms.tasks.zzh.addOnCompleteListener(Unknown Source)
                  at com.foo.foo.Common.DatabaseManager.getRemoteConfig(DatabaseManager.java:85)
                  at

I do not understand what is going. The related code:

private void getRemoteConfig() {
    remoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    remoteConfig.setConfigSettings(configSettings);
    remoteConfig.setDefaults(R.xml.remote_config_defaults);
    long cacheExpiration = 3600;

    //expire the cache immediately for development mode.
    if (remoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
        cacheExpiration = 0;
    }

    remoteConfig.fetch(cacheExpiration).addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                remoteConfig.activateFetched();
            }
            //LocalBroadcastManager.getInstance(null).sendBroadcast(new Intent(AppConstants.kNotificationonRemoteSettingsLoaded));*/
        }


    });
}

Graddle:

compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.android.support:appcompat-v7:25+'
compile 'com.google.android.gms:play-services-maps:9.6.1'

apply plugin: 'com.google.gms.google-services'
2

There are 2 answers

0
vinczu On

I've had the same problem. The issue was that I've used firebase remote config fetch before Super.oncreate(). Check where you call the getRemoteConfig() procedure!

0
Joseph .A. On

I currently noticed this issue when using Remote Config Firebase in my app.

I would say that on using the Remote Config to fetch data from firebase, the data overwrites the one in the app. If the data sent is bad, the one that previously existed is over-written and then crashes the app. If it's changed back to an error free one on Firebase, the app won't load up for Firebase Remote config to fix the error that is why most times if you clear cache of that app, it will work again.

I think they should introduce a wait time to handle crashes from error in remote or a fall back to avoid crashes in app.