简体   繁体   中英

Iabhelper crashes in Firebase Test lab on some devices

I receive the following error on 2 devices when testing my app in Firebase Test Lab, It goes well with 2 other devices:

java.lang.RuntimeException: Unable to start activity ComponentInfo{MyActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)


Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
at util.IabHelper.startSetup(IabHelper.java:267)
at MenuActivity.onCreate(MenuActivity.java:68)
at CameraActivity.onCreate(CameraActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
... 10 more

So it seems to be a problem coming from the initialization of IabHelper, here is the code where I set it up:

String base64EncodedPublicKey = "MyKey";

    mHelper = new IabHelper(this, base64EncodedPublicKey);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                           public void onIabSetupFinished(IabResult result)
                           {
                               if (!result.isSuccess()) {
                                   Log.d(TAG, "In-app Billing setup failed: " +
                                           result);
                               } else {
                                   Log.d(TAG, "In-app Billing is set up OK");
                               }
                           }
                       });

It works perfectly on my test phone and on the phone of my 2 alpha testers. Anybody has a clue about it?

So it was a bug that has been fixed, it seems I was using an older version of IabHelper. In case anyone looks for it, here what you need to change in IabHelper.java, line 267:

Replace:

if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {

with:

List<ResolveInfo> resolveInfoList = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
if (resolveInfoList != null && !resolveInfoList.isEmpty()) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM