I need help with "Google in-app" (SOLVED)

I get an error from Google Play: “Authentication needed. You must log in to your Google account”.

  1. It must have the same versionCode.
  2. Package names must be the same.
  3. You must sign with the same certificate and key.

1 & 2. The versionCode and package names were not modified from scratch.
3. I created and built a certificate and key using the “Creating certificates and keys” method.

I also applied Britzl’s advice.

And iap.buy (“android.test.purchased”), it worked fine.

I do not know what I’m missing. I need help.

Does it work on another phone? Have you tried clearing the cache and/or data of the Google Play Store app? Can you try and buy something in another app or on Google Play. Does that work?

1 Like

I have two phones and I tested both. It works but the payment window is maintained.

"Did you try to clear the cache and / or data in the Google Play Store app?"
I do not understand this, but I also tried clearing and running the app.

I can try and buy something in another app or on Google Play.

I did not write much code for in-app billing.

local function iap_listener(self, transaction, error)
    if error == nil then
        if transaction.state == iap.TRANS_STATE_PURCHASING then
            print("Purchasing...")
        elseif transaction.state == iap.TRANS_STATE_PURCHASED then
            print("Purchased!")
        elseif transaction.state == iap.TRANS_STATE_UNVERIFIED then
            print("Unverified!")
        elseif transaction.state == iap.TRANS_STATE_FAILED then
            print("Failed!")
        elseif transaction.state == iap.TRANS_STATE_RESTORED then
            print("Restored")
        end
    else
        print(error.error)
    end
end

function on_input(self, action_id, action)
    if action_id == hash("touch") and action.released then
    local node_7 = gui.get_node("node_7")
        if gui.pick_node(node_7, action.x, action.y) then
	     	gui.play_flipbook(node_7, "menu_middle")
	    	print("7 days free")
	   		-- Register the function that will listen to IAP transactions.
	        iap.set_listener(iap_listener)
	        -- Initiate a purchase of a coin...
			iap.buy("product_id")
        end
    end
end

What I mean is that the “Authentication needed. You must log in to your Google account” message comes from Android and Google Play, not Defold. A Google search: https://www.google.com/search?q=Authentication+needed.+You+must+log+in+to+your+Google+account returns many links where others have reported the same issue. Check this one for instance: https://www.androidpit.com/how-to-fix-google-play-authentication-is-required-error

1 Like

I did what you said, but the results are the same.

Is there anything more to do besides the code above?

No, that should be it. Can you add me (bjorn.ritzl@king.com) as a tester so that I can try the app as well?

1 Like

I know. But my project’s server is now localhost. No problem?

Note that the location where I entered the code is in “main / gui / story_stm / story_stm.gui_script”

I guess that would be a problem yes. Or can I get to the in-app purchase part without the game connecting to your server?

1 Like

I think so, but “android.test.purchased” is no problem.
Is this code usable even though the original server is not connected?

What do you mean? What’s the purpose of the server? Are you validating the receipt on the backend in your own server? The client code should in any case not change and the code you posted for purchasing an item looks ok. It must be a problem either with the configuration of your app and/or products or the Google account that you are using.

1 Like

I’m sorry I’m late. I was delayed connecting my app to the server.

Still, I can not solve the problem of in-app. I do not know what I’m missing.

My suggestion is that you follow the basic setup steps in this post and use a bare-bones test application. No, servers, no nothing. One button to buy one product. Nothing more. Does it work?

1 Like

Hold on. If you want to try In app purchases on Android there are a number of things you need to do:

  1. Create your app on Google Play. Fill out the Store Listing, Content Rating, Pricing & Distribution and most importantly In-app Products section.
  2. Upload a version of your app, signed with your release certificate as a Beta or Alpha test.
  3. Invite testers (in the APK section on Google Play)
  4. Each tester must click on the Opt-in URL to join the beta/alpha test (available in the APK section on Google Play, just below the list of invited testers)
  5. Publish your Beta/Alpha (no worries, it will only be visible and accessible by your testers, no one else)

These are the basic steps. Once you have those in place you can start doing local builds and rapidly deploy them to your device for testing. In order to test In-app purchases using local builds you need to make sure of the following:

  1. The locally built APK must be signed with the same release certificate as the APK you uploaded to Google Play
  2. The locally built APK must have the same package name as the APK you uploaded (as long as you don’t change the Package field in game.project this shouldn’t be an issue)
  3. The locally built APK must have the same version code as the APK you uploaded to Google Play
    With all the above in mind it simply won’t work to download dmengine.apk from d.defold.com, install it and try to use In App Purchases on Android. dmengine.apk is not signed with the same cert, it doesn’t have the same package name and not the same version code.


1.It will be released as beta in Google Play and you can download it as a tester account.
2.I created a “key” and a “certificate” exactly as in the manual. And when I built it, it was reflected.
3&4. I joined the tester by logging in to the url given as the tester account.
5. This is the same as No.1.

I tried downloading the app I uploaded from Google Play directly to my tester account and checked the in-app payment, but it still does not work.

Ok, can I try the app as well just to see the behavior myself?

1 Like

The problem is resolved.
first. When I downloaded it from Google Store and it was not paid: The problem is that I did not activate ‘In-app Product’.

second. I enabled ‘In-app Product’ but it was not paid. The problem is that I checked in real time with dmengine.apk. I built it myself and moved it to my phone and checked it out.

Thank you for your help.

3 Likes

Excellent. Good to hear that you managed to solve it!

1 Like