Android in App billing test purchase crashes Play store

I am currently developing an app with in App billing. all works fine. and I already published the app in Beta channel and tested it with test users with real items, and it works.

However while debugging, I am using the android.test.purchased item, my play store crashes when I press the buy button.

在这里输入图像描述

and I get the following error(s):

E/AndroidRuntime: FATAL EXCEPTION: main 
                        Process: com.android.vending, PID: 25463
                                                   java.lang.NullPointerException: Attempt to read from field 'com.google.android.finsky.protos.Acquisition$AutoDismissTemplate com.google.android.finsky.protos.Acquisition$PostAcquisitionPrompt.autoDismissTemplate' on a null object reference
                                                       at com.google.android.finsky.billing.SuccessStep.getLayoutResId(SuccessStep.java:75)
                                                       at com.google.android.finsky.billing.lightpurchase.PurchaseFragment.onStateChange(PurchaseFragment.java:31066)
                                                       at com.google.android.finsky.fragments.SidecarFragment.notifyListener(SidecarFragment.java:255)
                                                       at com.google.android.finsky.fragments.SidecarFragment.setState(SidecarFragment.java:250)
                                                       at com.google.android.finsky.billing.lightpurchase.CheckoutPurchaseSidecar.confirmAuthChoiceSelected(CheckoutPurchaseSidecar.java:631)
                                                       at com.google.android.finsky.billing.lightpurchase.PurchaseFragment.onStateChange(PurchaseFragment.java:32156)
                                                       at com.google.android.finsky.fragments.SidecarFragment.notifyListener(SidecarFragment.java:255)
                                                       at com.google.android.finsky.fragments.SidecarFragment.setState(SidecarFragment.java:250)
                                                       at com.google.android.finsky.billing.lightpurchase.CheckoutPurchaseSidecar.access$1900$2f730cd3(CheckoutPurchaseSidecar.java:72)
                                                       at com.google.android.finsky.billing.lightpurchase.CheckoutPurchaseSidecar$1.run(CheckoutPurchaseSidecar.java:1009)
                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                       at android.os.Looper.loop(Looper.java:148)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-23 02:22:43.202 590-739/? W/ActivityManager:   Force finishing activity com.android.vending/com.google.android.finsky.billing.lightpurchase.IabV3Activity


Purchase finished: IabResult: Null data in IAB result (response: -1002:Bad response received), purchase: null
Error purchasing: IabResult: Null data in IAB result (response: -1002:Bad response received)

sometimes the purchase continues after that, and other times, my app crashes.

I tested this on several devices (Nexus 7 with Android 6.0, Note 5 with Android 5.1.1, Galaxy S3 with Android 4.3, LG G3 with Android 4.4), all have the same behavior.

What makes me mad is that real in app items work flawlessly. which makes me think this means my code is fine. but having this happening with the test items, make me worried that it might be repeated with real items with real users when published.

I appreciate your assistance to let me know if I am doing something wrong leading to play store crashing, or this can happen?

please note that I am fairly new to Android development.

Thanks.

Here is my code for in App billing:

 ///... part of onCreate:

 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 {
                                               // Hooray, IAB is fully set up. Now, let's get an inventory of
                                               // stuff we own.
                                               Log.d(TAG, "Setup successful. Querying inventory.");
                                                mHelper.queryInventoryAsync(mGotInventoryListener);                                           }
                                       }
                                   });

/////////////////

public void startPurchase(String ITEM_SKU) { // Start the purchase process here

    String purchaseToken = "inapp:" + getPackageName() + ":"+ ITEM_SKU;

    Log.d(TAG, "Purchase started for : " + ITEM_SKU);

    mHelper.launchPurchaseFlow(this, ITEM_SKU, 10002,
                mPurchaseFinishedListener, purchaseToken);
}


// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        Log.d(TAG, "Purchase finished: " + result + ", purchase: "
                + purchase);
        if (result.isFailure()) {
            Log.d(TAG,"Error purchasing: " + result);
            if (result.getResponse()==7){
                if(myInventory.hasPurchase(ITEM_SKU))
                {
                    Log.d(TAG,"Ooops, Item already purchased, consume it");
                    mHelper.consumeAsync(myInventory.getPurchase(ITEM_SKU),mConsumeFinishedListener2);
                }
            }
            return;
        }

        Log.d(TAG, "Purchase successful.");

        if (purchase.getSku().equals(ITEM_SKU)) {
            mHelper.consumeAsync(purchase, mConsumeFinishedListener);

        }
    }
};

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result,
                                         Inventory inventory) {
        Log.d(TAG, "Query inventory finished.");

        if (result.isFailure()) {
            Log.d(TAG,"Failed to query inventory: " + result);
            return;
        }

        Log.d(TAG, "Query inventory was successful.");

        myInventory = inventory;
        //Process inventory


    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
        new IabHelper.OnConsumeFinishedListener() {
            public void onConsumeFinished(Purchase purchase,
                                          IabResult result) {

                if (result.isSuccess()) {
                    Log.d(TAG,"consume successful for " + purchase.getSku() + " & " + result.getMessage());
                    updateCoinsAndScore(coinsToAdd, 0);
                    Toast.makeText(getApplication(), "تم إضافة عدد " + coinsToAdd + " عملات إلى رصيدك", Toast.LENGTH_LONG).show();
                    //reset values
                    coinsToAdd=0;
                    ITEM_SKU="";
                } else {
                    Log.d(TAG, "Consume failed " + result.getMessage());                    }
            }
        };

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener2 =
        new IabHelper.OnConsumeFinishedListener() {
            public void onConsumeFinished(Purchase purchase,
                                          IabResult result) {

                if (result.isSuccess()) {
                    Log.d(TAG,"consumed, starting purchase again");
                    Log.d(TAG,"consume successful for " + purchase.getSku() + " & " + result.getMessage());

                    startPurchase(ITEM_SKU);

                } else {
                    Log.d(TAG,"Consume failed " + result.getMessage());                    }
            }
        };

The problem was in Google Play v6.0.0, it is now fixed in v6.0.5 (confirmed both on a Samsung and a Nexus device).

If you didn't get the Google Play update automatically, you can download it manually from ApkMirror.com etc.

链接地址: http://www.djcxy.com/p/30476.html

上一篇: 如何在django REST框架中修改request.data

下一篇: Android在应用程序结算测试购买崩溃Play商店