Testing the Google Play Billing Library

To recap, I’ve been working to update the Google Play Billing Library, because if I don’t update it by November 1, Google will lock the app and I’ll never be able to update it again. Pretty important.

When I left off last week, I’d rewritten a lot of code, but hadn’t been able to test it due to an infinite loop. This week, I was hoping to fix the infinite loop quickly and move on to the many bugs in my as-yet-untested billing library integration.

Tracking down the infinite loop

This was a tough bug. While it’s far from the toughest I’ve ever tracked down, it seemed mysterious enough that shortly before finding it, I was nearly ready to give up and look for a workaround. (There’s a motivational poster in there somewhere.) But I’m getting ahead of myself.

At first, I had almost nothing to go off of. The app would start, log a few unrelated messages, and then hang with a blank screen, with no clue as to why. The lag (and eventual “app not responding” message) tipped me off that it was an infinite loop, but that isn’t much to go on.

My biggest clue (or so I thought) was knowing what code most recently changed: the billing library. So somehow that must be looping forever, right? Well… I commented out the “connect to billing library” code, and nothing changed. I commented out more and more features of the library, followed by lots of other related and barely-related code, all to no avail.

I finally got the app to run by disabling all internet-related libraries and features (I have a compiler flag for that), but nothing short of that worked. I started to suspect that the mere presence of the billing library caused this error, even without using it in any way. I considered dropping all network features and releasing the app with no logins, purchases, or cloud saves, since that was starting to seem easier than tracking this down. Desperate times and all that.

Then I remembered I wasn’t out of debugging techniques just yet. Next up was version control. I could rewind the clock and get a version that worked, and carefully examine the changes from there. So I reverted the GPBL and my last few weeks of code, and compiled the app the way I’d had it working.

And it still froze. Huh.

This is a lesson I’ve learned many times over, but still sometimes forget. When something makes zero sense, you need to check your assumptions. I’d assumed that since this was a new error, my new code was at fault. But now my old code didn’t work either, and that meant I was looking in the wrong place.

I forget exactly what it was I did, but knowing this, I managed to make the app crash. That’s a good thing: with a crash comes an error message, and (at least in this case) a stack trace. This instantly narrowed the search down to a single line of code, and the line of code had nothing to do with billing.

Teaching my code patience

Turns out, I’ve been overlooking a significant issue for a while now. To make a medium-length story short, cloud save setup happens partway through the game’s setup process. I don’t know (or care) exactly when, because it shouldn’t matter.

At this point in the process, it sends a request to log in to PlayFab. You have to log in eventually if you want to use cloud saves, so I figured, might as well start it immediately so it can happen in the background. What I forgot is that Haxe’s network requests (usually) don’t happen in the background. Instead, the login command puts the rest of the setup process on hold until it connects.

Not only that, the moment you finish connecting, several different classes try to make use of the cloud data. But because game setup wasn’t done, some important variables were still null, including PlayFab.instance. When PlayFab.instance is null, it runs the PlayFab class constructor. The constructor sends a request to log in. After logging in, classes try to make use of the cloud data. But PlayFab.instance is still null… so it runs the constructor again. And again.

There’s a long-running programmer joke that you start out wondering why your code doesn’t work, and end up wondering how it ever worked. That’s me right now. (And I particularly relate to the second comment on that post: “Or if you change your code to make it work better, it doesn’t work, so you load your backup and your original code doesn’t work anymore…”)

The solution? Just don’t log in until the game is fully ready. A little bit of patience goes a long way. (I’ve also pushed a commit in case the infinite loop comes up elsewhere.)

Surprisingly, everything above only took a couple days. It felt like longer, but my computer’s clock disagrees.

Testing the GPBL (finally)

So my plan was, after resolving the infinite loop, I’d spend the rest of the week testing the billing code. This would provide lots more material for the epic conclusion to my “why developing for Android is so annoying” series.

But this plan failed, because I only ran into two problems. The first came with an error message, and the error message told me exactly how to fix it. The second required a bit of effort to figure out why things weren’t happening in order, but it wasn’t bad enough to blog about. And then… purchases just worked.

I spent nearly half the week just kind of waiting to see if Google Play would accept or reject the app. (Answer: reject. Google now insists on app bundles, so that’s what I’m working on next.)

So, uh… maybe mobile development isn’t quite as bad as I remember.

9 thoughts on “Testing the Google Play Billing Library”

  1. Sheesh I don’t understand why google has a punishment like NOT BEING ABLE TO UPDATE EVER AGAIN for not doing something, then makes it so hard to do that thing! Still, glad to hear you are doing well and actually alive bc last time I checked the most recent post was on the capitalization of run 3 so I was worried XD

  2. So great to hear from player 03 for the past few months after all this time. I play on iOS, since it is the only place I can get the full version. previously I used coolmath and player03.com but both end before even the I tunnel is a thing and player03.com stopped working like a week ago for some reason. Kongregate on my pc has the full version, but explore mode has no falling tiles in tunnels at all or character switching making the game unbeatable. (infinite mode works) Hopefully after we’ve resolved the google play business we can get a playable version of all of Run 3 on mouse n keyboard. if there are any updates on non-mobile Run 3 please let me know, either a community member or the man himself.

    damn nice problem solving skills

    and sick game bro

    1. Yeah, I don’t know why this site was under maintenance for about a week, either. I’m so relieved it’s back up right now! 😀

      Also, I agree that it would be nice to have the crumbling tiles back in the Kongregate version of Run 3 when playing in the SuperNova Player (in Explore Mode). Some gaps are too wide to cross without them, and floating outside the tunnels isn’t enough! 🙁 (And as much as I’d like the original gameplay back, it looks like we have to wait for more updates to the HTML5 remake.)

    1. Is this a coincidence that you found this right after I posted about the run 1 link that’s almost exactly the same? Cause I should have posted this link but I didn’t know is was needed by a bunch of people.

      1. Nope! After noticing that you posted the link to the Run 1 SWF file, I decided to edit the link so that it points to the Run 3 SWF, and as expected, it worked! 😀

        1. OK, thank you for clarifying that. Just so you know, I found those links (and many others) by using ctrl+u on a web page and using ctrl+f to find .swf. It works on basically anything other than coolmathgames and armor games. the Wayback machine can also help.

          1. You’re welcome! And the way I discover these SWF files is by pressing F12 to open the console and then Ctrl+F to search for instances of “.swf”. It can take a long time to find the correct file, but it’s worth the hassle! 😉 (I’ll also have to try your method at some point!)

Leave a Reply to Ricky Manzolina Cancel reply

Your email address will not be published. Required fields are marked *