Android in-app billing: custom sku purchase gives “Error - item not found”

后端 未结 4 1460
名媛妹妹
名媛妹妹 2021-01-03 14:35

I\'m trying to test in-app billing using my own sku/product ID \"upgrade_to_premium\". As I have seen recommended here, I am using the Dungeons sample app. I\'ve added a \"n

相关标签:
4条回答
  • 2021-01-03 14:51

    You have to publish the product (not the app) for this to work. And yes, you need to wait a bit. Presumably while your APK's state is replicated to all Google Play servers. It used to work right away about a year ago, but this is not the case any more. However, you don't need to upload and test the same APK, only the version and signature need to match. So, when you begin developing a new version, just bump the version in the manifest, export and upload a signed APK. Let it sit there while you develop and test. Then replace it with your final binary when publishing.

    0 讨论(0)
  • 2021-01-03 14:59

    You should note there are some very misleading errors and dialogs displayed in the demo Dungeons.java:

    --

    If you are getting "Error: This version of the application is not configured for Market billing."

    You must installed the RELEASE apk to your android DEVICE not emulator meaning:

    • Exporting your APK and signing it

    • Deleting any previous installation of your app on your device (even debug / developer versions!)

    • Side loading the APK to your device, installing it, and running it.

    • This also means debugging your released app is probably going to be without your debugger attached. If your debugger is attached, do tell me how!

    If you are getting "Error: Item not found", there's a decent chance there is nothing wrong.

    Dungeons.java actually has a bug in it. Let me explain:

    /**
     * Called when a button is pressed.
     */
    @Override
    public void onClick(View v) {
        if (v == mBuyButton) {
            if (Consts.DEBUG) {
                Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
            }
    
            if (mManagedType != Managed.SUBSCRIPTION &&
                     // ** The following line is bug when returns !true which is false, and then makes the if statement false
                    !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { 
                showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
    
                // ** Which then ends up running this else if, meaning it will try to purchase a subscription
            } else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
        } else if (v == mEditPayloadButton) {
            showPayloadEditDialog();
        } else if (v == mEditSubscriptionsButton) {
            editSubscriptions();
        }
    }
    

    Rather it should be written like this:

    /**
     * Called when a button is pressed.
     */
    @Override
    public void onClick(View v) {
        if (v == mBuyButton) {
            if (Consts.DEBUG) {
                Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
            }
    
            // We need this statement to evaluate to true on a Non-Subscription such as a Managed or Unmanaged Purchase
            if (mManagedType != Managed.SUBSCRIPTION) { 
    
                    // If the following errors out, show an error dialog.  However, it should not make the previous if statement false
                    if( !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { 
                        showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
                    }
    
            } 
    
             // This if statement gets run accidentally without the bug fix, thus trying to buy your "SKU" as a "subscription", which is totally wrong!
            else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) { 
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
        } else if (v == mEditPayloadButton) {
            showPayloadEditDialog();
        } else if (v == mEditSubscriptionsButton) {
            editSubscriptions();
        }
    }
    
    0 讨论(0)
  • 2021-01-03 15:08

    Set your public key in variable base64EncodedPublicKey in Security class.

    and use signed apk to test in app billing.

    0 讨论(0)
  • 2021-01-03 15:12

    Try this:

    Export your app as an APK file. Upload the APK to Google Play. Sideload the same APK to your test device. Wait an hour or so for Google Play to update its servers. Test the installed APK.

    0 讨论(0)
提交回复
热议问题