licensing.init( "google" ) failing? (getting false back)

Have been trying to get a response back from “licensing.verify” to no success. I just noted however that my licensing.init(“google”) is returning false.

Question - Any ideas why this would be the case & how to fault find.

The code I’m using is here. When I run this on my Android compiled code, and have uploaded an APK to google plan (not released), I get the “NotAttempted-InitFailed” response.

local function finishedFunction(displayObject, text)     displayObject.text = text end local infoString = "About to Call Google Play.  " local text = display.newText(infoString, 0, 0, display.contentWidth, display.contentHeight, native.systemFont, 12 ) text:setTextColor(255, 0, 0) local device = require("lib.device") if device.isGoogle then     local licensing = require( "licensing" )     local initResult = licensing.init( "google" )            -- \*\* RETURNS FALSE HERE \*\*\*      if initResult then         local function licensingListener( event )             local verified = event.isVerified             if not event.isVerified then                 infoString = infoString .. "\nOnGoogle: License Check: FAILED, " .. event.response .. ", " .. event.errorType                 native.requestExit()  --assuming this is how we handle pirates             else                 infoString = infoString .. "\nOnGoogle: License Check:PASSED"             end             finishedFunction(text, infoString)         end         licensing.verify( licensingListener )     else         infoString = infoString .. "\nGooglePlayLicenseCheck-NotAttempted-InitFailed"     end else     if device.isAndroid then         infoString = infoString .. "\nNOT On Google, but still an Android device"     else         infoString = infoString .. "\nGooglePlayLicenseCheck-NotAttempted-NotAndroid"     end     finishedFunction(text, infoString) end -- Just to show me the app is still running timer.performWithDelay(     2000,      function(event)         infoString = infoString.."."         finishedFunction(text, infoString)     end,     0)  

My code looks like this:

local onStartError = function(event) if (string.find("clicked,cancelled", event.action)) then native.requestExit(); end end local licensingListener = function(event) local verified = event.isVerified; local networkError = (event.errorType == "network"); if ((not verified) and (not networkError)) then print("ERROR: No valid licence"); audio.stop(); native.showAlert( "Error", "Sorry, no valid license found.\n".. "Please download the app again from the Google Play Store.", {"OK"}, onStartError); end end local licensing = require("licensing"); licensing.init("google"); licensing.verify(licensingListener);

Tks ingemar- my problem then is I’m not getting any response back at all to the listener. Any fault finding suggestions?

I see now that the docs say that true/false should be returned, however the sample doesn’t check that.

Try to call licensing.init(“google”) without checking the return value (or assume a true return value), and see if you get any further.

That’s what I had been doing for some time. But still never get a response back to the handler. No way to check for connection requests at the google end?

I can confirm that there’s a bug (or the docs are incorrect) as licensing.init() always return false, even on a device.

This means that the code you posted above will not work. You’ll need to remove the true/false check.

If you’ve already removed that after you posted the code above, then I’m not sure why your listener isn’t being called.

It should work. You must run it on a device though. Corona simulator will not work.

Yep. The code was only there in my last ditch attempt. And I’m testing on a device. Been through the tutorial and API and I can’t see what the problem is. Maybe I need to run up Wireshark or something and try to somehow put in between my device and Internet?

Actually I should be able to run the sample code, even without a real key, just to check no? Ie should get a response back still in this case?

Nope.

The key must be valid otherwise the callback isn’t called (I just checked myself).

Have you double-checked that the key in your config.lua is correct?

Mine is defined like this:

license = { google = { key = "very-long-string-on-one-line......", policy = "serverManaged" } }

key look valid.  Oh I note in terms of the uploaded APK versus what I’m now testing on (as I went through a few more iterations for what I have on the device testing), that:

 - version code (the integer) - is different (not sure why, might have been a type)

 - version name - matches

would this be an issue - would google not response because of this?  any other things need to match precisely

Version name doesn’t matter, but version code *must* be the same as on Google.

doh - ok I’ll update & retry - thanks - how did you build up this knowledge ingemar?  :)  is it documented somewhere

… how did you build up this knowledge ingemar?..

*Alot* of trial and error :slight_smile:

Sometimes I’d like to do a brain-dump, as I tend to forget things after a while :slight_smile:

just tried changes this but still no luck (I might have to go back and double-check everything to be sure), but is there anything else that comes to mind that has to match up?

  • is it just version code?

  • is it ok the app is not published

 - I did the self-signing thing when I built/build the apk using corona - can anything go astray here? 

 - support / excluded devices - I see this on Google Play - so I need to check the device I’m testing with are supported?   not too sure about this section - like if the app itself runs on the device already…

 - anything else?

PS also (just to add to my questions of desperation above) what is the concept re if users don’t have internet access when they run the app?  Do we let people play our apps if they can’t contact Google Play, or block them until they do?.. 

Anyway, licensing.init() *should* return true/false, so I’ve reported this bug to CoronaLabs.

It’s only the version code that needs to be the same and the App doesn’t need to be published.

Self-signed certificates are what I use.

Supported devices are just when you publish your apps, so you can control which devices you want to exclude/include. default is include all available devices depending on your manifest settings.

One other thing is that you need to use another Google account than your Android developer account on your device. You must set up test users in the Google Play developer console. Then you must make sure that your Android device is logged in as one of those users. Sometimes a factory reset of the device is needed to make a successful account change.

If there is no Internet connectivity, I just let them play. I know that some will exploit this, but I don’t think it’s worth pursuing to block. No matter how much effort you put in to anti-piracy some will always find a way around it. I’d rather spend my time creating new games…

Tks. So I’ve been using my dev account. Would this in itself prevent the response?

Wondering also does it have to be exactly the same build? I see a SHA hash against the version I uploaded.

You can have a different build. The main thing is that the version code is the same.

…ok… I’ve thought about another issue as well. Google Play server info lag. More info below…

What I do before testing is to create and upload an APK with the version code that I intend to use when I publish the app. Then I just leave it there during the whole testing process. It may also take several hours before that APK has propagated through Google’s system. Until then you will experience wonky behavior. Therefore I usually upload my draft APK the night before I start to do testing to ensure that all info has been propagated.

ok - perhaps that could be it, before for me it’s all been in the last say 9 hours I’d say…I’ll leave the same upload there overnight then and try again after that