Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
108 stars 83 forks source link

Error after publishing my game on googleplay #452

Closed Hai-San closed 6 years ago

Hai-San commented 7 years ago

Problem description

First: Sorry for bad English. I use Google translate.

Error after publishing my game on googleplay. I found a link that talks about a possible solution, but I do not know how it applies in the case of construct 3. My app uses the googleplay plugin to send and receive player scores.

The error happens only after the game is published. While I tested locally and by preview the error did not happen. For the preview I tested on 2 different phones and on my computer, and everything went well.

Attach a .c3p

It does not apply to this case. Game for test: Game

Steps to reproduce

Open the game and the error will appear on the screen.

Observed result

ctxag

Expected result

The error happens when the plugin tries to log in to googleplay. The correct thing would be for the game to be able to connect to the googleplay account to send and receive the scores.

Affected browsers

Any mobile device.

System details

Any mobile device.

Scott943 commented 7 years ago

I am not sure for Android, but I know that at the moment the Construct 3 team are currently working on new mobile iOS plugins, so the old ones may not be updated fully yet. Anyway isn't there a way to override the user agent, by putting this in your config.xml:

<preference name="OverrideUserAgent" value"Mozilla/5.0 Google" />

Hai-San commented 7 years ago

@Scott943 I'm compiling directly through construct 3. So at no time does the config.xml file appear to me. Is there any way I can track it yet? Using cocoon.io I know I have the option to change config.xml. But I do not know if it is possible to do this in construct 3.

Scott943 commented 7 years ago

In one of my iOS exports there is actually a config.xml under MainFile/GameTitle/Config.xml where I believe the command could work. I'm sure there is config.xml like that for Android too. Try placing the command alongside the other < preference > commandlines.

Hai-San commented 7 years ago

@Scott943 But I already create APK directly by C3. Is there any way to just compile to cordova and then play back on C3 to mount the .apk file? Thank you for trying to help me. :)

Scott943 commented 7 years ago

Okay I have looked at a Android version of it, and I think it would work best if you exported to an Android 'Project Only' file.

Under [GameName].cordova\res\xml you will find a config.xml file (at least thats what I found). Have a go with putting the command there :1st_place_medal:

Hai-San commented 7 years ago

I understand, the real problem will be to compile to an .apk file after making the change. I'm leaving my job now and coming home I'm going to try this solution. I was used to Intel XDK and Cocoon.io, however now I'm learning to do it manually and I'm still a bit slow with it. Thank you very much for your help. Thank you!

AshleyScirra commented 7 years ago

It looks like Google are blocking access to their service, so we might not be able to do anything about this...

Hai-San commented 7 years ago

@AshleyScirra I do not know if that's it. This same game I created in construct 2 and compiled with cocoon.io and this problem did not happen. So I transferred to construct 3 and used the native compiler, and this problem happened to happen. I'll try to solve it now and then leave the result here. Thanks :)

Scott943 commented 7 years ago

@AshleyScirra I still believe you can bypass it anyway?

AshleyScirra commented 7 years ago

Looks like we need to fake a browser UA in mobile apps.

shortercode commented 7 years ago

I had considered faking the browser UA, should be a fairly simple change to the cordova exporter and the build server for this. My main worry is how important google consider this, apps may be rejected during review due to security concerns. I believe the change was made to reduce the risk of applications scraping user credentials.

Hai-San commented 7 years ago

Yesterday I stayed for 5 hours trying to generate an APK file. I got no success. From what I read google has removed some functionality. So the tutorial I followed is no longer valid. tutorial When I get to step 9 an error happens. Even though I did step 8 it accuses the ANDROID_HOME does not exist. So I did not find another more current tutorial explaining how to generate an apk via CMD. Today after I leave work, I will suffer a few more hours to try to achieve some result. Or maybe I'll try to use the cocoon. Maybe it would be cool to offer an option on the dashboard to import a ZIP from an export cord. So I could download, make the changes and upload the files in construct 3 to create the APK.

Hai-San commented 7 years ago

Problem solved when inserting row in config.xml. I downloaded the .zip file for the android studio generated by the construct. Then I looked for the config.xml, added the line and then compiled using the android studio. The error has not occurred any more, however the way the game is connecting was strange. It does not prompt you to login as a normal application. I can not explain what is happening. In the preview I run the construct works perfectly without any problem.

Hai-San commented 7 years ago

But the login system is a bit strange. If you do not mind, download my game to reproduce the problem. Follow these steps: Note that at various times the app will request login into the account. 1 - Enter the game. 2 - Play once and then go to the score screen. 3 - On the punctuation screen click the exit button (The exit button function for the moment leads to the home layout)

It could be something I'm doing wrong. But it only occurs after generating the APK. In the preview none of this happens.

Code used for login:

[GOOGLE LOGIN] ----+ System: On start of layout

--------+ GooglePlay: Is loaded --------+ GooglePlay: [X] Is signed in ---------> GooglePlay: Sign in ---------> erro2: Set text to "conectou"

--------+ System: Else --------+ GooglePlay: Is loaded --------+ GooglePlay: Is signed in ---------> GooglePlay: Request social all-time hi-scores from googleScoreID (25 results, top) ---------> erro2: Set text to "conectado"

--------+ System: Else ---------> erro2: Set text to "nada"

----+ GooglePlay: On signed in -----> GooglePlay: Request social all-time hi-scores from googleScoreID (25 results, top)

----+ GooglePlay: On auto-sign in failed -----> LocalStorage: Check item LocalScoreID exists -----> erro: Set text to "erro auto sign"​&​GooglePlay.​ErrorMessage

@Scott943 @AshleyScirra @shortercode Sorry for my lack of knowledge. Thanks a lot for the help.

Hai-San commented 7 years ago

Even making some changes the error still happens. The app requests login multiple times. Current code: [GOOGLE LOGIN] ----+ GooglePlay: On loaded

--------+ GooglePlay: [X] Is signed in ---------> GooglePlay: Sign in

--------+ System: Else ---------> GooglePlay: Request social all-time hi-scores from googleScoreID (25 results, top)

----+ GooglePlay: On signed in -----> GooglePlay: Request social all-time hi-scores from googleScoreID (25 results, top)

----+ GooglePlay: On auto-sign in failed -----> LocalStorage: Check item LocalScoreID exists

shortercode commented 7 years ago

@MartDSam I'm trying to replicate your project locally, but I'm having some issues reading through your description of your eventsheet. Could you send me a PDF of it please?

On the eventsheet:

shortercode commented 7 years ago

also a debug mode APK of your project would be useful

Hai-San commented 7 years ago

@shortercode Here are the files: https://drive.google.com/open?id=0B2_o-ZpLFjWDQ0ptc1Z1M21YZzg Anything just call :)

shortercode commented 7 years ago

Nice! Thanks :)

Hai-San commented 7 years ago

@shortercode I added one more APK. This APK is identical to what is in my game in google play, but the debug version. It contains the additional line in config.xml: preference name="OverrideUserAgent" value="Mozilla/5.0 Google"

shortercode commented 7 years ago

I believe the error is being caused by an incorrect client_secret.

The network response that is causing the login to fail is

{
 "error": "invalid_client",
 "error_description": "Unauthorized"
}

As it actually shows the login screen with the app details correctly the client_id is correct, and there's nothing else labelled client I'm guessing it's the client_secret.

This is firing the On Error event, but you haven't got a handler for it in your GOOGLE LOGIN sheet.

In terms of odd timing "On loaded OR Is Signed in" is being called each time you enter the the score page hence why it's reappearing when the game over screen is being shown. It's kinda jarring to have it switch to the login page like that.

Hai-San commented 7 years ago

@shortercode Yes, 3 information is passed in googleplay plugin. App ID, client ID and client secret ID. But I'm sure the 3 are correct. In case I call the login function on multiple screens is not a problem, since I check if the user has already logged in or not. If you have logged in he simply ignores the function. Remembering that the client ID and the secret ID are credentials for Android. I think the line I'm inserting into config.xml makes the app run as a browser. However if I use the client ID and secret ID of the WEB credential an error occurs stating that the app is not allowed. But that same WEB credential I use locally for testing and works perfectly to send and receive information from google play. The difference is that I inserted the construct preview URL into the WEB credential in the URL list with permissions. Because the App does not have a URL, I can not give permission for it inside the credential. If I remove the line from config.xml the error that happens is the one that made me open this topic for discussion. How can we solve this?

shortercode commented 7 years ago

Ah so you think it's related to the hostname, that's definitely possible. I've just had a look through a google OAUTH app I have and I think the value which is causing problems here is Authorized JavaScript origins which limits the domain from which you can make network requests. Unfortunately cordova apps all run on the local filesystem which google doesn't accept as a valid location.

If this is the actual problem it's not going to be especially easy to work around. Let me get back to you...

Hai-San commented 7 years ago

@shortercode @AshleyScirra I'll leave a summary of everything so far then:

1 - Using google OAUTH for android app

--- a) The disallowed_useragent error happens, This error can be resolved by inserting the <preference name="OverrideUserAgent" value"Mozilla/5.0 Google" /> line inside the config.xml.

--- b) After inserting the line in the config.xml the error disallowed_useragent is solved, however we have the problem of request of login every time the user changes of layout. This problem occurs because google is not authenticating the login.

2 - Using google OAUTH for WEB

--- a) Everything works correctly in the local preview, the google play plugin can send and receive the information without any error, this is due to the fact that the construct preview URL is inserted in the OAUTH WEB Authentication panel as a permitted URL.

--- b) We tried to use the in-app OAUTH Web within google play, but there is an error in which the APP is not allowed. This is due to the fact that the APP does not have a URL to insert into the allowed URLs of the OAUTH web.

Now I do not know what we can do. I've tried everything that is within my reach. I use construct 2/3 to develop games due to my lack of time and the ease of the tool. But this mistake is making this all very tiring. Thanks to everyone who is trying to help.

If you need more files or information just ask.

shortercode commented 7 years ago

I'm sorry but I think this is going to be a while until we can fix it for android. I have to divert onto getting the IAP plugin finished.

Part of me still wonders if the client secret you had was in the wrong format ( the one I was looking at wasn't in the form AB : AB : AB like the one in your project ), I don't think it actually uses it when it's running on the web so it being wrong wouldn't necessarily break it on the web.

Hai-San commented 7 years ago

@shortercode edit removed the values just in case, I took a screenshot so I know what they look like

I'll change some characters just so I will not enter my exact key here.

Oauth Android: Client: ----------------------------------------.apps.googleusercontent.com Secret: --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--

Oauth WEB: Client: ----------------------------------------.apps.googleusercontent.com Secret: ---------------------------------------

shortercode commented 7 years ago

Should be using the Oauth web secret not android, as we're running it via a webview

shortercode commented 7 years ago

I think the plan is to replace it with a native one in the future, but we don't have time to rewrite half the plugin at the moment.

Hai-San commented 7 years ago

@shortercode Strange, I am 100% sure that I generated the 2 APks that I sent you using the oauth of the android. If I need to, I'll create the APKs again. But I can only do that when I get to my house. For me this is very bad, because it does not make sense to launch my game without I can make a system of scores and achievements. :/

shortercode commented 7 years ago

Using the WEB SECRET

Just to be extra clear, I know we're talking via google translate right now

Hai-San commented 7 years ago

Hahahah yes, very google translator. But what URL would I add to the WEB secret for my android application to be allowed to send and receive information?

Hai-San commented 7 years ago

@shortercode I think I got it wrong. You have stated that my APKs are using the oauth WEB. Arriving at home I send again the APKs with oauth android.

shortercode commented 7 years ago

No no no...

Your APK was using a secret in the form --:--:--:-- which appears to be android Cordova works in a WebView so it needs the web secret which is something like A7Eg1jip66Equ01xZy

For the URL add http://localhost to both and set the same in your game

Hai-San commented 7 years ago

@shortercode Aaaaaaaaa, I understand I'll try it then. I'll be back here as soon as I can. Sorry for the difficulty. Google translates is a little more complicated. Many thanks for your answers and for your patience.

shortercode commented 7 years ago

I'm always impressed google translate works as well as it does! If you really struggle to explain something we do have a guy who speaks Portuguese on the team!

Hai-San commented 7 years ago

Nice! In the next long answer I will send you a version in pt-br hahahaha. Although google translate sometimes does not translate exactly the phrase, it really has improved a lot in the last few years.

Hai-San commented 7 years ago

@shortercode

Unsuccessfully. In the credentials I was able to add localhost as a URL. However in the google play dashboard I can not add localhost as a url.

url_oauth url_oauth_2 url_oauth_3

Hai-San commented 7 years ago

@shortercode I still can not solve this problem. I've tried it in many ways, but none of it worked. :/

Hai-San commented 7 years ago

@shortercode I tried with 127.0.0.1. He agrees to save, but the problem still continues.

Hai-San commented 7 years ago

@shortercode @AshleyScirra I was now seeing my first game I created using construct 2 and compiled with Intel XDK. It works perfectly. And he's using OAUTH2 for android. Game works

Now what do I do? I have several games in the queue to be created, but I'm being stopped because of this problem. I understand it's a beta, however this is a bug that's keeping me from publishing my games. It's no crash that I give F5 and solve the problem. Believe me, every day I look for a solution and find nothing.

Sorry to bother you so much. :/

studioCloudb commented 7 years ago

Olá, li todo o seu problema. realmente acho muito complicado. Estou usando o construct3 e estou tendo um problema simples que é gerar o arquivo APK, ele simplesmente da ERRO BUILD APK terei q fazer da forma Manual como antes... Talvez esse link te ajude: https://www.scirra.com/tutorials/4846/building-with-cordova-part-02-build-an-android-app/page-9

Hai-San commented 7 years ago

@wmnjunior Eu já fiz esse ai, o problema nem está na compilação. O plugin que não está funcionando corretamente, parece que eles não testaram o plugin depois de pronto, pois não funciona pra ninguém no mobile. :/

Aergoyin commented 6 years ago

Hi @shortercode,

I was wondering if there has been any progress on this issue. Using Google Play Games is rather important for the games I am developing and the issue here is preventing me from releasing the games on the store. Just wondering if there would be a time frame or possible upcoming solution in order to adjust my project planning.

Thank you for your time.

AshleyScirra commented 6 years ago

If this comes down to the disallowed_useragent error, the problem is because Google started blocking access to the API we use in Android apps. We can work around it by essentially rewriting the entire plugin to use a different API, but that could take a while. It might be worth contacting Google and asking them to restore access so we don't have to do that.

Aergoyin commented 6 years ago

Hi @AshleyScirra,

Thank you for your prompt response with this. I am willing to contact Google about this however I am unsure exactly what to ask them. Is it to open access to allow construct 3 to use your current API for Google Play Games?

Furthermore, if the response is that they will not allow access, is there any chance that you and your team would redevelop this plugin. I understand this would take time to do, however a plugin which allows Google Play Games to work in the long term would be extremely beneficial and I think everyone here would really benefit from it.

Thank you again and I will continue using Construct 3 for my games as the new updates are fantastic, just wish the GPG would work :)

AshleyScirra commented 6 years ago

I think the issue is that Google have blocked access to the Google Play Games web API from Cordova apps. I'm not 100% sure this is the issue though, and I thought @shortercode had already put in a workaround for that. Rewriting the plugin is on the cards but we're all super busy right now with a lot of other things so I could not give an ETA, and obviously rewriting an entire plugin because Google arbitrarily pulled the plug on an API that previously worked is something we'd prefer to avoid.

Aergoyin commented 6 years ago

Thank you again @AshleyScirra,

I will contact Google and hope for a response to the issue. If @shortercode had put in a workaround, i am unsure as to what this is as I have tried this on my android device and I get the disallowed_useragent issue. If I opt to not include the client id and secret and instead just use the application id as Google suggests, then this does not seem to do anything when testing on Android.

Again, thank you for your time and if I hear something position back from Google, I will post here to inform everyone.

Aergoyin commented 6 years ago

Hi @AshleyScirra,

So I got a response from Google. Whether this is the actual issue or not I am not sure however maybe it will help with understanding the issue connecting to the Play Store using Construct 3.

Google: "I understand you have some concerns about using Cordova. If you are encountering issues you’ll need to upgrade your app to use Apache Cordova v.4.1.1 or higher. New apps or updates containing older versions of Apache Cordova will be blocked."

I don't know if this is an easy fix or if this is part of the rewriting of the app however they say the solution is to just upgrade Cordova. My knowledge of this is limited so I apologise about my naivety if this is more complicated that just an upgrade.

AshleyScirra commented 6 years ago

It's not to do with the Cordova version. All of C2 and C3's exports already use the latest Cordova version by default, which is currently v7, or possibly v6 in some older releases of C2, but we are certainly not using such an old version as v4.

shortercode commented 6 years ago

So to summarise this issue:

Construct uses the Google Play Games Web API. Historically this worked in a browser and in a webview. However, at some point Google blocked use of the Web API in webviews for "security" reasons.

To get around this I've rewritten this plugin to use the native API instead when running in a webview. This should fix the problem, but when creating your app with Google you need to set up your app as a native one not a web one. I will need to update the tutorial for this as there's a number of frustrating pitfalls ( surprise surprise ).

On the plus side some new actions for using native leaderboard and achievement dialogs now exist! They only work in the Android build though.

The fix actually snuck out in the r87 release without a changelog, so it can be tried now.

Pitfalls

If you miss something on this list, your unlikely to get anything other than a failed log in. I'd like to show more, but google doesn't give you anything to go on really.

Common errors I saw when one of the above wasn't done correctly:

8 - INTERNAL_ERROR An internal error occurred. Retrying should resolve the problem. ( Retrying doesn't really help ) 12501 - SIGN_IN_CANCELLED The sign in was cancelled by the user ( This one seems to happen without the sign in screen actually being shown to the user, so the description is also useless ) FATAL_DEVELOPER_ERROR ( Google Play Games Services was crashed by this, and nothing useful was sent to the game )