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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 16:33:17

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.

Set your public key in variable base64EncodedPublicKey in Security class.

and use signed apk to test in app billing.

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();
    }
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!