Google Plus Android SDK: Error inflating class com.google.android.gms.plus.PlusOneButton
Asked Answered
F

2

8

I use the Google Plus SDK in my Android app. On some rare devices, I have got the following crash when my view containing Google Plus buttons is inflated:

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

....
}

My GooglePlus buttons are in xml like this:

<com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
....
/>


<com.google.android.gms.plus.PlusOneButton
  xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
  android:id="@+id/plus_one_button"
  ...
   />

Below the log. Any idea on the way to solve this issue ?

Thanks !!

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.<init>(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.<init>(Unknown Source)
... 25 more

Examples of devices where I have got the issue (it happens only on few devices of each type otherwise I would have much more crash reports):

  • crane-a702jhorange
  • MW0712
  • Tablet S (nbx03)
  • List item
  • 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)
  • crane-inet
  • ITP-R208W (rk30sdk)
Flaring answered 21/11, 2013 at 18:25 Comment(3)
Since you say this doesn't happen on all devices, can you edit your question and provide the device type that you are experiencing the issue?Activate
@Regis_AG We see a lot of these too, did you ever find a solution?Fong
No, not found the origin of the problem. Anybody solved it ? Thanks.Flaring
R
0

I received an ACRA report from an rk2928sdk with the same exception. Fortunately I was storing the information from GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) in the report. This call returned SERVICE_INVALID.

I am using the PlusOneButton in a very basic "About" activity so I decided to duplicate this activity and remove the PlusOneButton from the layout second. Now I´m catching the InflateException and use the layout without the button if the exception gets catched.

@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;
}

The try-catch could be replaced by a check if .isGooglePlayServicesAvailable() returns a sane value. But I don't know which of those return values guarantee the availability of the PlusOneButton so I will leave it with the ugly try-catch.

Revival answered 2/12, 2014 at 21:20 Comment(1)
Is it possible to just use the normal CTOR instead of inflating ? Do you think it could help? Also, how do I report this to Google? The normal website is only for Android code, but not for Google-services...Yokel
E
0

Just add plus play service to you app:

    compile 'com.google.android.gms:play-services-plus:10.0.1' 
Exhibition answered 8/12, 2016 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.