Need to call ouya_plugin.initialize() first or the first call to any of the ouya_plugin callbacks fails silently

I am noticing some odd behavior when I call any of

callbacksFetchGamerUUID

callbacksRequestProducts

callbacksRequestPurchase

callbacksRequestReceipts

the first time.  It seems the CoronaOuyaFacade is not valid yet when the requests are sent and are failing without calling a callback.

I noticed the sample was behaving this way as well.  First click of the button doesn’t seem to return anything, but after that everything works.

I worked around this by calling initialize() first after launching the app.

The developer id needs to be set initially. I plan on adding something to the startup that auto calls the initialize.

https://devs.ouya.tv/developers/docs/corona

I/Corona (27538): plugin\_ouya.ouyaSetDeveloperId ([redacted]) I/OuyaCoronaPlugin(27538): setDeveloperId developerId: [redacted] I/Corona (27538): plugin\_ouya is initialized I/Corona (27538): Requesting receipts... I/Corona (27538): plugin\_ouya.asyncLuaOuyaRequestReceipts W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42a49870 I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.getReceiptsAsync I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.getReceiptsAsync: CoronaOuyaFacade is null W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42a1e7f8 W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42b364a0 I/PluginOuyaLuaLoader(27538): Detected developer id initializing... I/PluginOuyaLuaLoader(27538): OuyaCoronaPlugin initializing... I/OuyaCoronaPlugin(27538): InitializeTest: Unity has initialized, constructing TestOuyaFacade I/CoronaOuyaFacade(27538): Init([redacted]); V/OUYAF (27538): ODK version number: 62 I/CoronaOuyaFacade(27538): OuyaFacade.init(context, [redacted]); I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.InitializeTest: OuyaGameObject send SendIAPInitComplete

Here is the logcat of the startup of my application where asyncLuaOuyaRequestReceipts fails silently.  

This instance just happened even though I called initialize() (workaround I described above) first, so it appears the workaround is not 100% successful.

Looks like you initialized more than once or something weird there. You requested receipts and then set the developer id and then init again. That doesn’t seem right…

Try plugging in your package id and signing key into the example. Can you get receipts with that?

This is similar to the behavior I saw on the sample before I added the call to initialize().  The behavior I just described only seems to happen occassionally – i am not sure how to reproduce it 100% of the time.

Tee reason it looks like initialize() is being called twice is because:

  1. I call it at the beginning as a workaround

2. asyncLuaOuyaRequestReceipts calls initialize() as do all of the other methods in plugin_ouya

 – for some reason it seems “initialized” is not set to true when this second call occurs, so it tries to set it again

Only when I see “OuyaUnityPlugin.getReceiptsAsync: CoronaOuyaFacade is null” in the logcat do I see the problem.

k here’s some docs I wrote for this:

https://github.com/ouya/ouya-sdk-examples/blob/master/Corona/Submission/ouya/docs/ouya/index.markdown

And we are talking about the source here:

https://github.com/ouya/ouya-sdk-examples/blob/master/Corona/Submission/ouya/samples/InAppPurchasesPlugin/Corona/plugin_ouya.lua

– Invoke IAP Request Receipts and provide callbacks

plugin_ouya.asyncLuaOuyaRequestReceipts = function(onSuccess, onFailure, onCancel)

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    plugin_ouya.initialize();

    print (“plugin_ouya.asyncLuaOuyaRequestReceipts”);

    ouyaSDK.asyncLuaOuyaRequestReceipts(onSuccess, onFailure, onCancel)

end

Okay so it may call initialize() which will skip if it’s already true.

plugin_ouya.initialize = function ()

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    if plugin_ouya.initialized == false then

            plugin_ouya.ouyaSetDeveloperId(plugin_ouya.developerId);

            print “plugin_ouya is initialized”;

    end

end

and the first time it will set the developer id.

– Set IAP Developer ID

plugin_ouya.ouyaSetDeveloperId = function(developerId)

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    if plugin_ouya.initialized == true then

        return;

    end

    print (“plugin_ouya.ouyaSetDeveloperId (” … developerId … “)”);

    ouyaSDK.ouyaSetDeveloperId(developerId);

    plugin_ouya.initialized = true;

end

but your Java logcat says otherwise…

I wonder how soon you try to get receipts. Do you wait a couple seconds for the iap to initialize? You might be trying too fast…

Yes,here is what I currently do on app launch

call function that lists a bunch of information about the system

call plugin_ouya.ouyaSetDeveloperId()

load saved data

call plugin_ouya.asyncLuaOuyaRequestReceipts()

The reason I do this is because I am trying to check if an entitlement has been purchased so I can enable features you only get with that entitlement.  I want them to be available as soon as the user is ready to start.

Might I suggest.

  1. Wait two seconds:…

  2. call plugin_ouya.ouyaSetDeveloperId()

  3. load saved data

  4. Wait two seconds…

  5. call plugin_ouya.asyncLuaOuyaRequestReceipts()

It could be just happening too fast, since we have to wait for Java to initialize.

So far, everything is working fine with the waits added as you suggest.  May be worth adding something to the docs about adding a delay if calling these functions on app launch.

Sure thing. Glad to know it works!

The behavior has mysteriously returned after publishing the app to OUYA, even with the delays.  I am going to have to publish another version that times out if the callback isn’t called in some amount of time.

The developer id needs to be set initially. I plan on adding something to the startup that auto calls the initialize.

https://devs.ouya.tv/developers/docs/corona

I/Corona (27538): plugin\_ouya.ouyaSetDeveloperId ([redacted]) I/OuyaCoronaPlugin(27538): setDeveloperId developerId: [redacted] I/Corona (27538): plugin\_ouya is initialized I/Corona (27538): Requesting receipts... I/Corona (27538): plugin\_ouya.asyncLuaOuyaRequestReceipts W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42a49870 I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.getReceiptsAsync I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.getReceiptsAsync: CoronaOuyaFacade is null W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42a1e7f8 W/InputMethodManagerService( 316): Ignoring showSoftInput of uid 10018: com.android.internal.view.IInputMethodClient$Stub$Proxy@42b364a0 I/PluginOuyaLuaLoader(27538): Detected developer id initializing... I/PluginOuyaLuaLoader(27538): OuyaCoronaPlugin initializing... I/OuyaCoronaPlugin(27538): InitializeTest: Unity has initialized, constructing TestOuyaFacade I/CoronaOuyaFacade(27538): Init([redacted]); V/OUYAF (27538): ODK version number: 62 I/CoronaOuyaFacade(27538): OuyaFacade.init(context, [redacted]); I/OuyaCoronaPlugin(27538): OuyaUnityPlugin.InitializeTest: OuyaGameObject send SendIAPInitComplete

Here is the logcat of the startup of my application where asyncLuaOuyaRequestReceipts fails silently.  

This instance just happened even though I called initialize() (workaround I described above) first, so it appears the workaround is not 100% successful.

Looks like you initialized more than once or something weird there. You requested receipts and then set the developer id and then init again. That doesn’t seem right…

Try plugging in your package id and signing key into the example. Can you get receipts with that?

This is similar to the behavior I saw on the sample before I added the call to initialize().  The behavior I just described only seems to happen occassionally – i am not sure how to reproduce it 100% of the time.

Tee reason it looks like initialize() is being called twice is because:

  1. I call it at the beginning as a workaround

2. asyncLuaOuyaRequestReceipts calls initialize() as do all of the other methods in plugin_ouya

 – for some reason it seems “initialized” is not set to true when this second call occurs, so it tries to set it again

Only when I see “OuyaUnityPlugin.getReceiptsAsync: CoronaOuyaFacade is null” in the logcat do I see the problem.

k here’s some docs I wrote for this:

https://github.com/ouya/ouya-sdk-examples/blob/master/Corona/Submission/ouya/docs/ouya/index.markdown

And we are talking about the source here:

https://github.com/ouya/ouya-sdk-examples/blob/master/Corona/Submission/ouya/samples/InAppPurchasesPlugin/Corona/plugin_ouya.lua

– Invoke IAP Request Receipts and provide callbacks

plugin_ouya.asyncLuaOuyaRequestReceipts = function(onSuccess, onFailure, onCancel)

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    plugin_ouya.initialize();

    print (“plugin_ouya.asyncLuaOuyaRequestReceipts”);

    ouyaSDK.asyncLuaOuyaRequestReceipts(onSuccess, onFailure, onCancel)

end

Okay so it may call initialize() which will skip if it’s already true.

plugin_ouya.initialize = function ()

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    if plugin_ouya.initialized == false then

            plugin_ouya.ouyaSetDeveloperId(plugin_ouya.developerId);

            print “plugin_ouya is initialized”;

    end

end

and the first time it will set the developer id.

– Set IAP Developer ID

plugin_ouya.ouyaSetDeveloperId = function(developerId)

    if ouyaSDK == nil then

        print “ouyaSDK named java functions are not initialized”;

        return;

    end

    if plugin_ouya.initialized == true then

        return;

    end

    print (“plugin_ouya.ouyaSetDeveloperId (” … developerId … “)”);

    ouyaSDK.ouyaSetDeveloperId(developerId);

    plugin_ouya.initialized = true;

end

but your Java logcat says otherwise…

I wonder how soon you try to get receipts. Do you wait a couple seconds for the iap to initialize? You might be trying too fast…

Yes,here is what I currently do on app launch

call function that lists a bunch of information about the system

call plugin_ouya.ouyaSetDeveloperId()

load saved data

call plugin_ouya.asyncLuaOuyaRequestReceipts()

The reason I do this is because I am trying to check if an entitlement has been purchased so I can enable features you only get with that entitlement.  I want them to be available as soon as the user is ready to start.

Might I suggest.

  1. Wait two seconds:…

  2. call plugin_ouya.ouyaSetDeveloperId()

  3. load saved data

  4. Wait two seconds…

  5. call plugin_ouya.asyncLuaOuyaRequestReceipts()

It could be just happening too fast, since we have to wait for Java to initialize.