v3 mini控制器的向后兼容性:错误膨胀类片段

时间:2016-08-07 11:55:51

标签: android chromecast google-cast


在谷歌CastVideos参考应用程序minSdkVersion是10.当尝试在API 16仿真器实例(Android 4.1 x86)上运行应用程序时,应用程序立即崩溃,我收到此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.sample.cast.refplayer/com.google.sample.cast.refplayer.VideoBrowserActivity}: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                  at android.app.ActivityThread.access$600(ActivityThread.java:130)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:4745)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:511)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                  at com.google.sample.cast.refplayer.VideoBrowserActivity.onCreate(VideoBrowserActivity.java:111)
                  at android.app.Activity.performCreate(Activity.java:5008)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:4745) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: java.lang.RuntimeException: com.google.android.gms.internal.zzsb$zza: No acceptable module found. Local version is 0 and remote version is 0.
                  at com.google.android.gms.internal.zzni.zzbg(Unknown Source)
                  at com.google.android.gms.internal.zzni.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:2074)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1264)
                  at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1366)
                  at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2409)
                  at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
                  at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
                  at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
                  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.google.sample.cast.refplayer.VideoBrowserActivity.onCreate(VideoBrowserActivity.java:111) 
                  at android.app.Activity.performCreate(Activity.java:5008) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:4745) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: com.google.android.gms.internal.zzsb$zza: No acceptable module found. Local version is 0 and remote version is 0.
                  at com.google.android.gms.internal.zzsb.zza(Unknown Source)
                  at com.google.android.gms.internal.zzni.zzbg(Unknown Source) 
                  at com.google.android.gms.internal.zzni.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:2074) 
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061) 
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1264) 
                  at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1366) 
                  at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2409) 
                  at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120) 
                  at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374) 
                  at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33) 
                  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.google.sample.cast.refplayer.VideoBrowserActivity.onCreate(VideoBrowserActivity.java:111) 
                  at android.app.Activity.performCreate(Activity.java:5008) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:4745) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                  at dalvik.system.NativeStart.main(Native Method) 

它可以像AppCompatActivity一样不会膨胀由Cast v3 Framework提供的MiniController Fragment。

这是Cast Framework的问题还是某种错误配置的模拟器?

同样的情况发生在我自己的应用程序中,我也将Mini Controller Fragment添加到AppCompatActivity中。
在API 23上,两个应用程序都运行良好。

由于

2 个答案:

答案 0 :(得分:0)

问题是模拟器图像没有Google API(没有实际支持库和应用程序崩溃的播放服务)

答案 1 :(得分:0)

您需要检查google-play-services版本,如果版本与您正在开发应用程序的版本不同,则会崩溃。为避免这种情况,您可以使用以下代码段来检查设备上当前安装的版本,并启动一个对话框来更新google-play-services

/**
 * Check play services version and go for update if not updated
 * @return
 */
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else{
            Toast.makeText(this, "This device is not supported", Toast.LENGTH_LONG).show();
            finish();
        }
        return false;
    }
    return true;
}