Kindle shows blank screen on store.init()

I have an app on google play and am currently in process of adding it to amazon store, however I am having problems with the Amazon IAP This is the code I am using (taken mostly from the corona docs) everything works on android but on the kindle it shows a black screen as soon as i call store.init. The logcat only shows the print message “after require” and then proceeds to the black screen.

main.lua

local function transactionCallback( event ) local transaction = event.transaction local tstate = event.transaction.state -- --Google does not return a "restored" state when you call store.restore() --You're only going to get "purchased" with Google. This is a work around --to the problem. -- --The assumption here is that any real purchase should happen reasonably --quick while restores will have a transaction date sometime in the past. --5 minutes seems sufficient to separate a purchase from a restore. -- if store.availableStores.google and tstate == "purchased" then local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") if timeStamp + 360 \< os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. tstate = "restored" restoring = false end end if tstate == "purchased" then myData.isPaid = true mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") native.showAlert("Thank You!", "Your transaction was successful! Thank you for your support!", {"Okay"}) store.finishTransaction( transaction ) composer.hideOverlay() elseif tstate == "restored" then myData.isPaid = true mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) composer.hideOverlay() elseif tstate == "refunded" then myData.isPaid = false mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "revoked" then -- Amazon feature --Revoke this SKU here: mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") elseif tstate == "cancelled" then native.showAlert("Transaction Cancelled", "The transaction has been cancelled, you were not charged.", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "failed" then store.finishTransaction( transaction ) else store.finishTransaction( transaction ) end end local function loadProductsListener( event ) print("In loadProductsListener") local products = event.products for i=1, #event.products do print(event.products[i].title) print(event.products[i].description) print(event.products[i].localizedPrice) print(event.products[i].productIdentifier) end for i=1, #event.invalidProducts do print(event.invalidProducts[i]) end end -- Initialize the store if system.getInfo("targetAppStore") == "amazon" then store = require "plugin.amazon.iap" print("after require") store.init( transactionCallback ) print("after init") store.loadProducts({"com.company.game"}, loadProductsListener) print("after load") store.restore() else if store.availableStores.apple and not mySettings.isPaid then timer.performWithDelay(1000, function() store.init( "apple", transactionCallback); end) end if store.availableStores.google and not mySettings.isPaid then timer.performWithDelay( 1000, function() store.init( "google", transactionCallback ); restoring = true; store.restore(); end ) end end

I have an overlay script which handles the store.purchase. Any help with this would be grealy appreciated as this is the only thing keeping me from submitting the app.

Hi,

Can you post the logcat from the app running on the Kindle?

Do you have the Amazon SDK Tester installed?

-Preston

I/Corona  (21063): working…

V/Corona  (21063): > Class.forName: plugin.amazon.iap.LuaLoader

V/Corona  (21063): < Class.forName: plugin.amazon.iap.LuaLoader

V/Corona  (21063): Loading via reflection: plugin.amazon.iap.LuaLoader

I/Corona  (21063): after require

and no I do not have the Amazon SDK Tester installed, i wasnt sure if its required just to init the store?

Thanks for the quick response and your time =D

L ES 2.0 V@45.0 AU@ (CL@3851443) V/Corona (22470): \> Class.forName: plugin.amazon.iap.LuaLoader V/Corona (22470): \< Class.forName: plugin.amazon.iap.LuaLoader V/Corona (22470): Loading via reflection: plugin.amazon.iap.LuaLoader I/Corona (22470): after require I/PurchasingManager(22470): Purchasing Framework initialization complete. Build ID 1.0.3 D/PurchasingManager(22470): In App Purchasing SDK - Sandbox Mode: PurchasingObse rver registered: plugin.amazon.iap.CoronaPurchasingObserver@40f5d220 D/SandboxRequestHandler(22470): In App Purchasing SDK - Sandbox Mode: sendGetUse rIdRequest W/ActivityManager( 809): Unable to start service Intent { act=com.amazon.testcl ient.iap.appUserId flg=0x10000000 (has extras) } U=0: not found D/SurfaceTexture( 413): [Starting com.gmail.bgranger08.Nanny\_s\_Bingo] setFilter ingEnabled called with mCurrentTextureBuf == NULL I/ChargeProtectionService( 809): New full charge capacity, adjust charge curren t I/ChargeProtectionService( 809): New charge current: 3074 mA I/ActivityManager( 809): No longer want jp.co.omronsoft.iwnnime.mlaz (pid 22151 ): empty #17 I/ActivityManager( 809): No longer want com.android.keychain (pid 22137): empty #18 V/BatteryDrain( 809): sending alarm Alarm{41153408 type 0 com.amazon.venezia}

Sorry here is the full logcat not just the corona ><

Here is the hint:

W/ActivityManager( 809): Unable to start service Intent { act=com.amazon.testclient.iap.appUserId flg=0x10000000 (has extras) } U=0: not found

During development, you must always have the SDK Tester if you are interacting with any of the store APIs, including init. init() registers your callback with the Amazon SDK Tester during development and with the Amazon Appstore Client when the app is downloaded from the Amazon Appstore. Please install the SDK Tester and let me know if you have any more issues.

-Preston

After installing the SDK Tester it now works! Thanks again for the help, one more question. I installed the amazon.sdktester.json file, how would i use that in purchase to test it?  would it just be store.purchase(“amazon.sdktester.json”)?

Forgive me, I am still new to the in app purchase APIs 

Hi,

Have you looked at this page? https://developer.amazon.com/appsandservices/apis/earn/in-app-purchasing/docs/testing-iap

In your amazon.sdktester.json you should define the same skus that you will define at developer.amazon.com when you publish your app. For example, if you have a sku called ‘com.myapp.myiapitem’, you should define this in amazon.sdktester.json. When testing your app, when buying this item you should call store.purchase(“com.myapp.myiapitem”).

When you are ready to publish your app, define this same SKU at developer.amazon.com with the description and image you would like your users to see, and you’re done. You can use the same code for testing and when published in the Amazon Appstore. You do not need to use a different sku for testing and for production like you might with other IAP services.

-Preston

Thanks again for all the help,

I have already made the in app item on the amazon developer page, and used the JSON file generate button. I then used adb to push that amazon.sdktester.json file onto my using 

adb push amazon.sdktester.json /mnt/sdcard/amazon.sdktester.json

Now i copied the SKU from the json file and used it in the store.purchase(“com.company.myapp.myitem”) and when I press the button that calls the purchase nothing happens and nothing is gettin reported on the logcat. Again I’m sorry for all the trouble =P and really appreciate all the time you have taken to help me!

EDIT: I think I found the problem, I am init the store in main.lua, but I don’t call store.purchase until my mainmenu.lua which is loaded after main is done. The mainmenu.lua doesn’t have a require “store” so Im thinkin thats the problem, but for some reason it works just fine on the google store… I move the store.purchase to the end of my main just to see and the app opens and shows the purchase and then crashes when you close the purchase or complete the purchase…Ill upload logcat in a moment if needed…

Are you sure you are calling store.purchase(sku)? You should see either a similar intent message for the intent ‘com.amazon.testclient.iap.purchase’ or possibly an error if you are calling store.purchase();

-Preston

I have found the source of the crashing after cancel or purchase, I was using the code from this site:

http://coronalabs.com/blog/2013/09/03/tutorial-understanding-in-app-purchases/

Near the top of the transactionCallback it checks for Google restoration by calling

 if store.availableStores.google and tstate == "purchased" then local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") if timeStamp + 360 \< os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. print("map this purchase to a restore") tstate = "restored" print("I think tstate is ", tstate) restoring = false end end

The crash was coming from checking store.availableStores since the Amazon IAP doesn’t provide it, i just added a quick if statement around it like this:

 if system.getInfo("targetAppStore") ~= "amazon" then if store.availableStores.google and tstate == "purchased" then local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") if timeStamp + 360 \< os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. tstate = "restored" restoring = false end end end

and everything works just fine. Im not sure if thats the best way to handle it or not but it works…

Also yes I am calling store.purchase(sku) but I think the reason was because it was in a different script that didnt have the store required.

Ok that makes sense, looks like your app was crashing before calling purchase. I am glad you solved your issue, but please do not hesitate to create a new topic or reply to this one if you run into more issues.

-Preston

I do have one quick question. The SKU im using is an entitlement, how do I reset it back to not purchased? everytime i try to purchase it says i already own it.

EDIT: Disregard that, I had a moment, obviously thats what the SDK tester.apk is for =P

You may open the SDK tester and clear the test user’s purchases, or clear the data for the Amazon SDK Tester, whichever is more convenient. 

Hi,

Can you post the logcat from the app running on the Kindle?

Do you have the Amazon SDK Tester installed?

-Preston

I/Corona  (21063): working…

V/Corona  (21063): > Class.forName: plugin.amazon.iap.LuaLoader

V/Corona  (21063): < Class.forName: plugin.amazon.iap.LuaLoader

V/Corona  (21063): Loading via reflection: plugin.amazon.iap.LuaLoader

I/Corona  (21063): after require

and no I do not have the Amazon SDK Tester installed, i wasnt sure if its required just to init the store?

Thanks for the quick response and your time =D

L ES 2.0 V@45.0 AU@ (CL@3851443) V/Corona (22470): \> Class.forName: plugin.amazon.iap.LuaLoader V/Corona (22470): \< Class.forName: plugin.amazon.iap.LuaLoader V/Corona (22470): Loading via reflection: plugin.amazon.iap.LuaLoader I/Corona (22470): after require I/PurchasingManager(22470): Purchasing Framework initialization complete. Build ID 1.0.3 D/PurchasingManager(22470): In App Purchasing SDK - Sandbox Mode: PurchasingObse rver registered: plugin.amazon.iap.CoronaPurchasingObserver@40f5d220 D/SandboxRequestHandler(22470): In App Purchasing SDK - Sandbox Mode: sendGetUse rIdRequest W/ActivityManager( 809): Unable to start service Intent { act=com.amazon.testcl ient.iap.appUserId flg=0x10000000 (has extras) } U=0: not found D/SurfaceTexture( 413): [Starting com.gmail.bgranger08.Nanny\_s\_Bingo] setFilter ingEnabled called with mCurrentTextureBuf == NULL I/ChargeProtectionService( 809): New full charge capacity, adjust charge curren t I/ChargeProtectionService( 809): New charge current: 3074 mA I/ActivityManager( 809): No longer want jp.co.omronsoft.iwnnime.mlaz (pid 22151 ): empty #17 I/ActivityManager( 809): No longer want com.android.keychain (pid 22137): empty #18 V/BatteryDrain( 809): sending alarm Alarm{41153408 type 0 com.amazon.venezia}

Sorry here is the full logcat not just the corona ><

Here is the hint:

W/ActivityManager( 809): Unable to start service Intent { act=com.amazon.testclient.iap.appUserId flg=0x10000000 (has extras) } U=0: not found

During development, you must always have the SDK Tester if you are interacting with any of the store APIs, including init. init() registers your callback with the Amazon SDK Tester during development and with the Amazon Appstore Client when the app is downloaded from the Amazon Appstore. Please install the SDK Tester and let me know if you have any more issues.

-Preston

After installing the SDK Tester it now works! Thanks again for the help, one more question. I installed the amazon.sdktester.json file, how would i use that in purchase to test it?  would it just be store.purchase(“amazon.sdktester.json”)?

Forgive me, I am still new to the in app purchase APIs 

Hi,

Have you looked at this page? https://developer.amazon.com/appsandservices/apis/earn/in-app-purchasing/docs/testing-iap

In your amazon.sdktester.json you should define the same skus that you will define at developer.amazon.com when you publish your app. For example, if you have a sku called ‘com.myapp.myiapitem’, you should define this in amazon.sdktester.json. When testing your app, when buying this item you should call store.purchase(“com.myapp.myiapitem”).

When you are ready to publish your app, define this same SKU at developer.amazon.com with the description and image you would like your users to see, and you’re done. You can use the same code for testing and when published in the Amazon Appstore. You do not need to use a different sku for testing and for production like you might with other IAP services.

-Preston

Thanks again for all the help,

I have already made the in app item on the amazon developer page, and used the JSON file generate button. I then used adb to push that amazon.sdktester.json file onto my using 

adb push amazon.sdktester.json /mnt/sdcard/amazon.sdktester.json

Now i copied the SKU from the json file and used it in the store.purchase(“com.company.myapp.myitem”) and when I press the button that calls the purchase nothing happens and nothing is gettin reported on the logcat. Again I’m sorry for all the trouble =P and really appreciate all the time you have taken to help me!

EDIT: I think I found the problem, I am init the store in main.lua, but I don’t call store.purchase until my mainmenu.lua which is loaded after main is done. The mainmenu.lua doesn’t have a require “store” so Im thinkin thats the problem, but for some reason it works just fine on the google store… I move the store.purchase to the end of my main just to see and the app opens and shows the purchase and then crashes when you close the purchase or complete the purchase…Ill upload logcat in a moment if needed…