If Crashlytics shows an IllegalStateException with the message “This stopwatch is already running” coming from the Play Billing Library, you have hit a known bug in version 8.0.0 that shows up when automatic service reconnection is enabled. Google marked it fixed from 8.1.0 on, and I moved my app to 8.3.0. Here is what the crash looked like, how I connected it to the library, and what to check in your own project.
What the crash looked like
I check Crashlytics for every new release. For our Mahjong game Tilelings the report was tiny: two events from one user, only on version 1.1.0, and every other number in the dashboard was clean. The exception was an IllegalStateException with the text “This stopwatch is already running”. The top stack frames were inside obfuscated Billing Library classes, in the callback that runs when the billing service disconnects.
Two events from one person is easy to ignore. I did not ignore it, because a crash inside a library you do not control tends to be a bug, not bad luck, and it can hit more people later.
Why I suspected the library, not my code
Nothing in my own code uses a stopwatch. The message comes from timing code inside the library. In my billing class the client is built with automatic service reconnection turned on, and my own disconnect callback is empty on purpose, because the library is supposed to reconnect by itself. So the only moving part at the crash site was the library's reconnect logic.
What the issue tracker says
Searching for the exact message led to a public Google issue about this crash in Play Billing 8.0.0 with automatic reconnection. It is the same combination I use. The thread says the problem is fixed in version 8.1.0 and later. The release notes do not mention it, so you only find it by searching the tracker. The issue was marked fixed, reopened and fixed again, which is a reminder to read the latest comments before you trust a status.
The fix: one line in the version catalog
The change itself is tiny. In the Gradle version catalog the Billing dependency moves from 8.0.0 to 8.3.0, the app version code goes up, and a new release goes out. I picked 8.3.0 instead of a 9.x release because a major version can change APIs, and I wanted a fix for one crash, not a migration.
At the time of writing the new build has only just reached the store, so I cannot show a long clean record yet. I will look at Crashlytics again after a few days of real use and update this note if the crash comes back.
A workaround if you cannot upgrade
If you must stay on 8.0.0, the logical workaround is to stop using automatic reconnection and reconnect yourself inside the disconnect callback, with a short delay between attempts. I did not test this, so treat it as an idea, not as a recommendation. Upgrading is simpler and is what Google points to.
How to check your own apps
- Search the Crashlytics issue list for the text “stopwatch is already running”.
- Look at the Billing version in your Gradle files. Anything at 8.0.0 is affected only if automatic reconnection is also on.
- Search your code for the automatic reconnection call on the client builder.
- Upgrade to 8.1.0 or later, test a purchase flow on a real device and release.
- Watch the next releases in Crashlytics, not only the first day.
What I did for the rest of my apps
Seven more of my games and apps use the same Billing version together with the same reconnection setting. They have no reports yet, but they carry the same risk, so I am updating them in one batch. A rare crash in a purchase library is worth fixing before it becomes a pattern.
FAQ
What does “This stopwatch is already running” mean?
It is an IllegalStateException thrown by timing code inside the Play Billing Library when a timer is started while it is already running. In version 8.0.0 it could happen during automatic service reconnection.
Which Play Billing versions are affected?
Reports point to 8.0.0 with automatic service reconnection enabled. Google’s tracker says it is fixed from 8.1.0 on.
Do I need to move to Billing 9?
No. A 8.x version such as 8.3.0 fixes this crash without a major API migration.
How often does it happen?
Rarely. In my case it was two events from one user. Rare crashes in a billing library are still worth fixing.
If you want to see this in action, Tilelings is free on Google Play and needs no account. More notes like this one live on my site.
Top comments (1)
Good catch tracing it back through the stack instead of dismissing two events from one user. Crashes in a reconnect callback usually depend on how often the Play service connection drops, so low volume now may just reflect a small sample. Did you notice whether it happened right after the app came back from background?