3

I try to configure Chromecast but got RuntimeException and don't understant the reason. Here are logs from Fabric:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{... .activity.TVActivityPhone}: java.lang.RuntimeException: com.google.android.gms.dynamite.DynamiteModule$zza: Remote load failed. No local fallback found. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2747) at android.app.ActivityThread.access$900(ActivityThread.java:187) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5877) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) Caused by java.lang.RuntimeException: com.google.android.gms.dynamite.DynamiteModule$zza: Remote load failed. No local fallback found.

And here is my code:

protected void configureCast() {
        mCastContext = CastContext.getSharedInstance(this); // here I've got RuntimeException
        if(mCastContext != null) mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
        mSessionManagerListener = new CastSessionManagerListener(this);
        mSessionManagerListener.setCastConnectionListener(mCastConnectionListener);
    }

Here is build.gradle:

    compile 'com.google.android.gms:play-services-gcm:10.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-cast-framework:10.2.0'

Any help?

alla
  • 529
  • 5
  • 20
  • Make sure that you initialized properly your activity in your manifest file. You can check in this [thread](http://stackoverflow.com/questions/16584049/android-fatal-exception-main-java-lang-runtimeexception-unable-to-start-activi) the possible causes of your error. Also, maybe you are using big image that caused memory problems. You must scale down your image as specified [here](http://stackoverflow.com/questions/28525268/fatal-exception-main-java-lang-runtimeexception-unable-to-start-activity-a-lot). – abielita Mar 14 '17 at 08:20
  • 1
    Are you still experiencing this issue? I started getting the same issue after updating the compat library to v26.x – user1026605 Sep 02 '17 at 06:15
  • @user1026605, are you still experiencing this issue? – Sabrish Sep 27 '17 at 01:51
  • I'm also experiencing this. – user1796260 Sep 27 '17 at 11:50
  • @user1796260 do you have the logs trace for this issue? – Sabrish Sep 27 '17 at 17:16
  • I'm having the exact same stacktrace than the one in the question except that it never happened before – user1796260 Sep 28 '17 at 07:54
  • @Sabrish Did you find the solution for your problem? – sam_k Oct 11 '17 at 00:38
  • @user1796260 did you find the solution for this problem? – sam_k Oct 11 '17 at 00:38

1 Answers1

9

First of all, it's not related to wrong project configuration as described in Why I get this error when on google map "Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class?.


One day I got a spike (~1300 crash in 1 day) in crashes in Fabric with com.google.android.gms.dynamite.DynamiteModule$zza: Remote load failed. No local fallback, com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0 exceptions.

It wasn't clear to me from the first look why it happened as I didn't ship any update of the application during that period of time. After deeper investigation (few days in total) I have found that the issue is caused by broken compatibility between Google Play Services version and outdated Google Cast SDK.

My Android application used 10.2.4 version of Google Cast SDK and this version is not compatible with some Google Play Services versions. I have found that 11.3.02 (480-161239932) version of Google Play Service is not compatible with 10.2.4 Google Cast SDK. There are (for sure) other versions of Google Play Services which are not compatible with Google Cast SDK library, but I found just one and it was enough for testing and further fix.

Having 11.3.02 (480-161239932) version of Google Play Services installed on the device my application was crashing immediately upon start. Worth noting, that I have found other applications on my device which were crashing immediately upon start and stack trace was the same.

Fix for the crash

Fix was simple for me - I had to update Google Play Services from 10.2.4 to 11.4.2, in particular play-services-cast-framework, play-services-ads, firebase-core, firebase-messaging.


Spikes history in Fabric:

  • September 25 (~400 crashes), first spike
  • September 27 (~200 crashes)
  • September 29 (~140 crashes)
  • October 8 (~1300 crashes)

After October 8th crash wasn't that critical (~10-20 crashes per day) and no more spikes observed. This means that users updated Google Play Services and application didn't crash anymore on start.

Once I updated the Google Play Services version and users updated to new version of application - crash disappeared (~1-2 crashes per day).

Explanation of why this crash occured

As you may know, Google Play Services are automatically updated in background. This means that one day users can receive update of Google Play Services which is not compatible with Google Cast SDK used in application and application will crash (100%).

From my experience, it happens for Google Cast SDK, but might be the case with other libraries (no proofs).

Application crashes when you are calling any method from Google Cast SDK. I have commented different places in my application which rely on Google Cast SDK and application was always crashing.

Detailed guide

If someone is curious how to mimic this crash, here's detailed guide.

  • First of all, we need to uninstall existing version of Google Play Services. This can be achieved from "Google Play Services" application info screen downgrade of google play services
  • Install 11.3.02 (480-161239932) version of Google Play Services on Android device (apkmirror link).

    adb install -r com.google.android.gms_11.3.02_(480-161239932)-11302480_minAPI23(x86,x86_64)(nodpi)_apkmirror.com.apk

  • Open application and observer application crash when Google Cast SDK accessed.

2nd arrival of the crash

I thought that I have fixed the crash by update Google Play Services, but few weeks after silence I've got notification that crash with the same stacktrace resurfaced.

After some investigation (few days again) I was able to reproduce the issue. And here are the sad news - I can do nothing about this crash :sad_face: or at least I didn't find elegant solution yet.

Good news are that resurfaced crash appearance is very rare (~1-2 crashes per month).

Google Play Services auto-update or force uninstall (less probable) force stops open application to take effect of Play Services update. This is an uncontrollable process, which means that Android OS can install silently Google Play Services at any time. If the user has application open and Google Play Services installation finishes at some point, an application will be killed by the system and user needs to reopen it. When an application is killed by the system, we can see in logs exact the same stacktrace for the crash as we had for the 1st case. It's hard to reproduce and happened to me only a few times. But this case is more probably as Google Play Services are getting updates quite often.

Though there's a way to reproduce this crash (less probable in real life) - "removal of Google Play Services updates from device". It produces the same stacktrace.

So basically, we need to start removal of Google Play Services updates and quickly (I mean really quick) open our application. If we succeed, the application will be killed by the system upon start as Google Play Services were removed and system kills the application.

And here's the stacktrace:

FATAL EXCEPTION: main
Process: XXX, PID: 26149
java.lang.RuntimeException: Unable to start activity ComponentInfo{XXX/XXX.SomeActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2733)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2819)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6321)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
 Caused by: java.lang.RuntimeException: com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0.
    at com.google.android.gms.internal.zzavl.zzbp(Unknown Source)
    at com.google.android.gms.internal.zzavl.zza(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source)
    at com.google.android.gms.cast.framework.media.uicontroller.UIMediaController.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.media.widget.MiniControllerFragment.onCreateView(Unknown Source)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
    at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1645)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1390)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1640)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1896)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3673)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:331)
    at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:65)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at XXX.SomeActivity.setContentView(SomeActivity:XXX)
    at XXX.SomeActivity.onCreate(SomeActivity:XXX)
    at android.app.Activity.performCreate(Activity.java:6760)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)

Update

There was a Google Play Services 12.0.0 release, which supposes to fix the issue:

Fixed a bug where calling CastContext.getSharedInstance() on devices with out-of-date versions of Google Play services caused a crash. Outdated Google Play services versions still cause the method to fail, so clients should check for an appropriate version.

But in fact, even after updating to 12.0.0 version I'm seeing lots of crashes. Crashes occur when there's an update of Google Play Services is happening on the device. To workaround this issue, we need to check if Cast API is available by checking if an Exception is not thrown when we call Cast API.

fun isCastApiAvailable(): Boolean {
    val isCastApiAvailable = isNotTv(context)
            && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
    try {
        CastContext.getSharedInstance(context)
    } catch (e: Exception) {
        // track non-fatal
        return false
    }
    return isCastApiAvailable
}

This way we prevent the crash. The application might be killed and restarted by the system if Play Services update happens when the application is in the foreground. Alternatively, Cast API related features won't be available (Chromecast icon is not visible). So we avoid the crash this way and report as non-fatals just to have understanding how often this situation happens.

Veaceslav Gaidarji
  • 4,261
  • 3
  • 38
  • 61
  • 1
    even after adding a check like above and having an exception handlers its still crashing. any idea? its majorly happening in Chinese devices as far as I have observed – praveen seela Jun 17 '21 at 04:31