title: Android: Crash when setting up media route button
body: <p>I'm having pretty much the same problem as <a href="https://stackoverflow.com/questions/39257813/android-cast-sdk-v3-crashing-in-release-build-only">Android: Cast SDK v3 Crashing in Release build only</a>.
  The key difference is that my project does it while i'm just debugging and does it on this line</p>
  
  <pre><code>CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mMediaRouteButton);
  </code></pre>
  
  <p>I have tried making all my variables public but that doesn't do anything. The full code is</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mMediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
      CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mMediaRouteButton);
  
      mCastContext = CastContext.getSharedInstance(this);
  
      mSelector = new MediaRouteSelector.Builder()
              // These are the framework-supported intents
              .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
              .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
              .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
              .build();
      mMediaRouter = MediaRouter.getInstance(this);
  }
  </code></pre>
  
  <p>Also I find it worth mentioning that this code worked and I can not for the life of me figure out what caused it to stop working. As far as I can tell it stopped working when I invalidated the cache in Android Studio.
  This is the error I'm getting</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage.package/mypackage.package.MainActivity}: java.lang.IllegalStateException: Failed to initialize CastContext.
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
      at android.app.ActivityThread.-wrap12(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6077)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
      Caused by: java.lang.IllegalStateException: Failed to initialize CastContext.
      at com.google.android.gms.cast.framework.CastContext.zzbb(Unknown Source)
      at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source)
      at com.google.android.gms.cast.framework.CastButtonFactory.setUpMediaRouteButton(Unknown Source)
      at mypackage.package.MainActivity.onCreate(MainActivity.java:51)
      at android.app.Activity.performCreate(Activity.java:6664)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:154) 
      at android.app.ActivityThread.main(ActivityThread.java:6077) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
      Caused by: java.lang.IllegalAccessException: java.lang.Class&lt;mypackage.package.CastOptionsProvider&gt; is not accessible from java.lang.Class&lt;com.google.android.gms.cast.framework.CastContext&gt;
      at java.lang.Class.newInstance(Native Method)
      at com.google.android.gms.cast.framework.CastContext.zzbb(Unknown Source) 
      at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source) 
      at com.google.android.gms.cast.framework.CastButtonFactory.setUpMediaRouteButton(Unknown Source) 
      at mypackage.package.MainActivity.onCreate(MainActivity.java:51) 
      at android.app.Activity.performCreate(Activity.java:6664) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:154) 
      at android.app.ActivityThread.main(ActivityThread.java:6077) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
  </code></pre>