Note: If you are a regular Harrison Farm reader, most of the terminology will probably look like Greek. (From Marathon: “But you’ll probably want to read it for the sake of the italicized portion at the midpoint.” ) If you are a frustrated app developer, this may save you up to 1.5 hours of waiting for Android Studio to restart, not to mention 10 hours of debugging.
Note 2: This bug only happens when one is using a custom view in an XML file. If you don’t even need to use the XML display, the bug shouldn’t hinder you in any way.
One day I was coding along my merry way when I opened up an XML and flipped over to display mode. That was when I was confronted by the message: “Waiting for build to finish…”
What this message even means, I’m not sure. It seems to be referring to the Gradle build, but nothing was building at the moment. I gave it a little time and nothing happened.
I went off on a big, huge rabbit trail which took me through restarting Android Studio ~40 times. I found the culprit XML file, I did some trial-and-error until I found that the problem was in a custom view Java file of mine. So I did some more trial-and-error to find out that the problem didn’t seem to be in my code at all. It was just some mysterious problem with that specific file.
And this brings the story to a sad chapter in my life. After around 3 weeks of trying to defeat this bug, I finally lost momentum and just stopped coding … for about four months. I had tried reverting Android Studio to an older version, I’d tried to modify the compiling scripts, I’d tried learning Kotlin (a Java alternative). So I just gave up. I could’ve asked Carman for help, but I had lost momentum and my sense of motivation.
4 months later, Marathon gave me some encouragement and told me that I would have extra chores until I had solved this bug, and that he was willing to help me any way he could. Sure enough, this gave me the motivation I needed. After about a week, I broke through.
Don’t let your momentum stop. What wouldn’t I give for 4 whole months of (nearly) bugless coding.
Next I went through some more trials and errors (this time having to delete and recreate a new file + restarting Android Studio with each trial) until I found the root of all my problems: a simple uninitialized variable.
What do I take away from this?
Problems with Android Studio:
- They didn’t give me a NullPointerException error. They didn’t say anything about my error either in the XML error boxes or during the Gradle build.
- If you open display mode in only one bad XML file, all others get the same problem: Infinitely “Waiting for build to finish”. The only way to reset this is to restart Android Studio.
- If you try to display a bad custom view in an XML file and the XML file gets the “Waiting for build to finish” error, that file is forever infected with the “Custom View Curse”, as I call it. Even if you fix the error in the Java code, somehow the XML will always fail on that file forever. In order to rid a custom view Java file of the Custom View Curse you have to… well, you actually can’t. You have to copy the code, delete the file with the Custom View Curse, create a new Java file with the same name, then paste in your old code. The Curse is invisible, as far as I know. It’s probably in the file metadata or something.
Android Studio isn’t perfect. The problem isn’t always you.
Leave a Reply