实时应用程序测试中的Amazon In App Purchase无法正常工作

时间:2019-06-16 17:42:42

标签: in-app-purchase amazon amazon-fire-tv

我在Live App Testing中的Amazon In App Purchase中遇到一些问题。自最近4到5天以来,我一直处于这种状态,尝试了许多解决方案,但无法继续前进。我在应用购买SDK中使用了Amazon。我采用了Amazon SDK随附的示例项目。我已经更改了它的SKU,对于本地测试,我是Appigner,并且应用程序运行正常。现在,我已经在Live App测试中上载了应用,并在亚马逊帐户上创建了IAP项目,然后Live app测试上的App停止工作。

活动onResume代码在下面-

 @Override
    protected void onResume() {
        super.onResume();
        sampleIapManager.activate();
        Log.d(TAG, "onResume: call getUserData");
        PurchasingService.getUserData();
        Log.d(TAG, "onResume: getPurchaseUpdates");
        PurchasingService.getPurchaseUpdates(false);

        System.out.println(TAG + " onResume: call getProductData for skus: " + MySku.values());
        final Set<String> productSkus = new HashSet<String>();
        for (final MySku mySku : MySku.values()) {
            System.out.println("TAG , SKU information = "+mySku.getSku());
            productSkus.add(mySku.getSku());
        }
        PurchasingService.getProductData(productSkus);

    }

商店中定义的SKU json-

{
  "com.amazon.sample.iap.subscription.mymagazine.quarter": {
    "smallIconUrl": "https://com-amazon-mas-catalog.s3.amazonaws.com/amzn1.devportal.fileupload.6b3d68d2073e4bfb9f9d273448d51cc6_23d65d61-4fb7-44bd-b7c1-aeb6bc885981_09a3dbc2307fb170a718a981c150c1f1",
    "title": "Subscription Plan",
    "itemType": "SUBSCRIPTION",
    "price": 12,
    "description": "Subscription to My Magazine",
    "languageTitleMap": {
      "US": "Subscription Plan"
    },
    "languageDescriptionMap": {
      "US": "Subscription to My Magazine"
    },
    "currencyPriceMap": {
      "US": 0
    },
    "subscriptionParent": "com.amazon.sample.iap.subscription.mymagazine"
  },
  "com.amazon.sample.iap.subscription.mymagazine.month": {
    "smallIconUrl": "https://com-amazon-mas-catalog.s3.amazonaws.com/amzn1.devportal.fileupload.6b3d68d2073e4bfb9f9d273448d51cc6_23d65d61-4fb7-44bd-b7c1-aeb6bc885981_09a3dbc2307fb170a718a981c150c1f1",
    "title": "Subscription Plan",
    "itemType": "SUBSCRIPTION",
    "price": 5,
    "description": "Subscription to My Magazine",
    "languageTitleMap": {
      "US": "Subscription Plan"
    },
    "languageDescriptionMap": {
      "US": "Subscription to My Magazine"
    },
    "currencyPriceMap": {
      "US": 0
    },
    "subscriptionParent": "com.amazon.sample.iap.subscription.mymagazine"
  }
}

代码中的MySku.java-

    package com.example.sampleiap;
/**
 * 
 * MySku enum contains all In App Purchase products definition that the sample
 * app will use. The product definition includes two properties: "SKU" and
 * "Available Marketplace".
 * 
 */
public enum MySku {

    //The only subscription product used in this sample app
    MY_MAGAZINE_SUBS("com.amazon.sample.iap.subscription.mymagazine", "US"),
    MY_MAGAZINE_SUBS_MONTH("com.amazon.sample.iap.subscription.mymagazine.month", "US"),
    MY_MAGAZINE_SUBS_QUARTER("com.amazon.sample.iap.subscription.mymagazine.quarter", "US");

    private final String sku;
    private final String availableMarkpetplace;

    /**
     * Returns the Sku string of the MySku object
     * @return
     */
    public String getSku() {
        return this.sku;
    }

    /**
     * Returns the Available Marketplace of the MySku object
     * @return
     */
    public String getAvailableMarketplace() {
        return this.availableMarkpetplace;
    }

    private MySku(final String sku, final String availableMarkpetplace) {
        this.sku = sku;
        this.availableMarkpetplace = availableMarkpetplace;
    }

    /**
     * Returns the MySku object from the specified Sku and marketplace value.
     * @param sku
     * @param marketplace
     * @return
     */
    public static MySku fromSku(final String sku, final String marketplace) {
       /* if (MY_MAGAZINE_SUBS.getSku().equals(sku) && (null == marketplace || MY_MAGAZINE_SUBS.getAvailableMarketplace()
                .equals(marketplace))) {
            return MY_MAGAZINE_SUBS;
        }*/

        return MY_MAGAZINE_SUBS.getSku().equals(sku) && (null == marketplace || MY_MAGAZINE_SUBS.getAvailableMarketplace()
                .equals(marketplace)) ? MY_MAGAZINE_SUBS :

                (MY_MAGAZINE_SUBS_MONTH.getSku().equals(sku) && (marketplace == null || MY_MAGAZINE_SUBS_MONTH.getAvailableMarketplace().equals(marketplace)))
                ? MY_MAGAZINE_SUBS_MONTH : (MY_MAGAZINE_SUBS_QUARTER.getSku().equals(sku) && (marketplace == null || MY_MAGAZINE_SUBS_QUARTER.getAvailableMarketplace().equals(marketplace))) ? MY_MAGAZINE_SUBS_QUARTER : null;

    }

}

Build.gradle代码-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.sampleiapus"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/in-app-purchasing-2.0.76.jar')
}

Proguard文件-

-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*
-optimizations !code/allocation/variable

如果proguard文件不包含优化!代码/分配/变量 然后,当我单击购买按钮时,它向我显示一个错误对话框。

enter image description here

如果我将 -optimizations!code / allocation / variable 放在一行,那么我就没有onPurchase事件。请帮我。自最近5天以来,我一直陷在其中。预先感谢

1 个答案:

答案 0 :(得分:0)

您是否在Amazon开发人员控制台上提交了IAP项目?它们的状态应为“实时”,否则您的应用程序将无法在运行时检索它们。我怀疑是导致错误消息的原因。

如果这不是问题,则检查logcat应该有助于确定根本原因。