Google Plus Android SDK:错误导致类com.google.android.gms.plus.PlusOneButton

我在Android应用中使用Google Plus SDK。 在一些罕见的设备上,当我的包含Google Plus按钮的视图膨胀时,我遇到了以下崩溃:

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // CRASH HERE .... } 

我的GooglePlus按钮是xml,如下所示:

   

在日志下面。 在解决这个问题的方法上有什么想法吗?

谢谢 !!

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.audioguidia.myweather/com.audioguidia.myweather.MyWeatherActivity}: android.view.InflateException: Binary XML file line #111: Error inflating class com.google.android.gms.plus.PlusOneButton 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 #111: Error inflating class com.google.android.gms.plus.PlusOneButton at android.view.LayoutInflater.createView(LayoutInflater.java:613) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) at android.app.Activity.setContentView(Activity.java:1867) at com.audioguidia.myweather.MyWeatherActivity.onCreate(MyWeatherActivity.java:419) at android.app.Activity.performCreate(Activity.java:5008) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) ... 11 more Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:417) at android.view.LayoutInflater.createView(LayoutInflater.java:587) ... 22 more Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.Resources.getValue(Resources.java:1013) at android.content.res.Resources.getDrawable(Resources.java:658) at com.google.android.gms.plus.PlusOneDummyView$b.getDrawable(Unknown Source) at com.google.android.gms.plus.PlusOneDummyView.(Unknown Source) at com.google.android.gms.internal.bu.a(Unknown Source) at com.google.android.gms.plus.PlusOneButton.d(Unknown Source) at com.google.android.gms.plus.PlusOneButton.(Unknown Source) ... 25 more 

我遇到问题的设备示例(它只发生在每种types的少数设备上,否则我会有更多的崩溃报告):

  • 起重机a702jhorange
  • MW0712
  • 平板电脑S(nbx03)
  • 项目清单
  • Galaxy Y(GT-S5360B)
  • Galaxy Y Duos(GT-S6102)
  • rk2928sdk
  • rk2928sdk
  • rk2928sdk
  • Galaxy Note II(t03g)
  • Galaxy Mini(GT-S5570I)
  • e1901_v77_jdt1_9p017_fwvga
  • Nexus S(crespo)
  • Galaxy Ace(GT-S5830i)
  • 起重机INET
  • ITP-R208W(rk30sdk)

我收到了来自rk2928sdk的ACRA报告,但有相同的例外情况。 幸运的是,我在报告中存储了来自GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)的信息。 此调用返回SERVICE_INVALID

我在一个非常基本的“关于”活动中使用PlusOneButton ,因此我决定复制此活动并从布局中删除PlusOneButton 。 现在我正在捕获InflateException并在没有按钮的情况下使用布局,如果exception被捕获的话。

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView; try { rootView = inflater.inflate(R.layout.activity_about, container, false); } catch (InflateException e) { rootView = inflater.inflate(R.layout.activity_about_fallback, container, false); } return rootView; } 

如果.isGooglePlayServicesAvailable()返回一个合理的值,则可以通过检查来替换try-catch 。 但是我不知道哪些返回值保证了PlusOneButton的可用性,所以我将把它留给丑陋的try-catch

只需为您的应用添加plus播放服务:

  compile 'com.google.android.gms:play-services-plus:10.0.1'