android-branch-deep-linking-attribution: [android] play console reports thousands of crashes due to branch

The Play Console reports thousands of crashes of our app due to Branch.

Crash reports:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6864)
  at android.app.ActivityThread.access$1300 (ActivityThread.java:268)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1982)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:7814)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)
Caused by: java.lang.IllegalStateException: 
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:485)
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:461)
  at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:184)
  at io.branch.referral.PrefHelper.<init> (PrefHelper.java:172)
  at io.branch.referral.PrefHelper.getInstance (PrefHelper.java:190)
  at io.branch.referral.Branch.<init> (Branch.java:399)
  at io.branch.referral.Branch.initInstance (Branch.java:791)
  at io.branch.referral.Branch.getBranchInstance (Branch.java:624)
  at io.branch.referral.Branch.getAutoInstance (Branch.java:695)
  at com.example.CustomApplicationClass.onCreate (CustomApplicationClass.java:18)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1190)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6859)
java.lang.RuntimeException: 
  at android.app.ActivityThread.handleMakeApplication (ActivityThread.java:7189)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:7134)
  at android.app.ActivityThread.access$1600 (ActivityThread.java:274)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2102)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:8167)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:496)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)
Caused by: java.lang.IllegalStateException: 
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:486)
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:462)
  at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:184)
  at io.branch.referral.PrefHelper.<init> (PrefHelper.java:172)
  at io.branch.referral.PrefHelper.getInstance (PrefHelper.java:190)
  at io.branch.referral.Branch.<init> (Branch.java:399)
  at io.branch.referral.Branch.initInstance (Branch.java:791)
  at io.branch.referral.Branch.getBranchInstance (Branch.java:624)
  at io.branch.referral.Branch.getAutoInstance (Branch.java:695)
  at com.example.CustomApplicationClass.onCreate (CustomApplicationClass.java:18)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1190)
  at android.app.ActivityThread.handleMakeApplication (ActivityThread.java:7184)

and similar ones

Happens mostly on Android 10 (~70%), Android 9 (~20%) and Android 8.

I have tried using version 5.0.0 and 5.0.3, but results are the same.

My CustomApplicationClass looks like this:

package com.example;

import android.content.Context;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import io.branch.referral.Branch;

public class CustomApplicationClass extends MultiDexApplication {

  @Override
  public void onCreate() {
    super.onCreate();

    // Branch logging for debugging
    Branch.enableLogging();

    // Branch object initialization
    Branch.getAutoInstance(getApplicationContext());
  }

  @Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }
}

MainActivity looks like this (simplified):

public class MainActivity extends AppCompatActivity {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override public void onStart() {
        super.onStart();
        Uri data = getIntent() != null ? getIntent().getData() : null;
        Branch.sessionBuilder(this).withCallback(callback).withData(data).init();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        this.setIntent(intent);
        Branch.sessionBuilder(this).withCallback(callback).reInit();
    }

    private Branch.BranchReferralInitListener callback = new Branch.BranchReferralInitListener() {
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
                Log.i("BRANCH SDK", referringParams.toString());
            } else {
                Log.i("BRANCH SDK", error.getMessage());
            }
        }
    };

}

So nothing strange there as far as I am aware. I suspect it really is an error in the Branch code.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 2
  • Comments: 18 (1 by maintainers)

Most upvoted comments

Awesome. We are planning on releasing today.