Android development makes me angry sometimes

So I’m working on making an Android version of my baseball win expectancy finder, and things are going pretty well! (anyone want to beta test it??) Except…

I’m using Xamarin.Forms so I can write all my code in C#/XAML, which is neat! I was even able to add Google ads in just an hour or two thanks to this handy guide after some fighting with NuGet packages.

Then I decided to build it in Release and deploy it to my actual phone, and it started to crash on launch. The Debug version didn’t have this problem, and launching the Release build through the debugger did not give any useful information, but after some Binging and fiddling with some project settings I managed to at least see that it was crashing with an Android.Views.InflateLayoutException. Sadly there was no data in the exception or call stack or anything.

So, OK, I figured there must be something with my XAML, so I commented out everything except the main TabbedPage control, but that didn’t help. At a loss, I went back to Bing and Google (yes, pulling out the big guns!) and after looking through a bunch of links and trying a handful of random things I looked more closely at the log and saw a line like

W/resourcetype: entry identifier 0x14c is larger than 0x84

So OK, this looks bad, I guess, and after some more Bing/Googling, I stumble across a this StackOverflow question that points to this Google Groups thread with a suggestion that this is a bug in “HistoryRecord over in the framework” (?) is trying to read the theme, and there isn’t anything wrong with your code. So I try this suggested workaround of adding this to the top of styles.xml:

<style name=”Stub”></style>
<style name=”Stub1″></style>
<style name=”Stub2″></style>
<style name=”Stub3″></style>
<style name=”Stub4″></style>
<style name=”Stub5″></style>
<style name=”Stub6″></style>

These don’t do anything, they’re just there to try to work around the bug.

This didn’t work, but I figured “in for a penny, in for a pound” and added a few more, which also didn’t work. Then I changed them to the self-terminating XML tag form <style name="Stub" /> and lo and behold, the crash went away!

The kicker? That Google Groups post was from 9 years ago. This bug, which causes a crash on startup with no obvious cause and requires a basically-impossible-to-guess workaround has been around for at least 9 years.

*incoherent muttering*

ThumbnailCopy for Firefox (and how Firefox is awesome now!)

Many moons ago, I wrote a Firefox extension to make it easy to copy an image inside a link, which is handy when posting images from a Gallery or whatnot. Since then, the Firefox extension API has changed significantly, so it stopped working a while ago.

I was inspired to revive it because Firefox Quantum just came out, and it’s much faster than it used to be! If you switched to Chrome for performance reasons, I’d invite you to check out Firefox again – it’s good to have an ecosystem of web browsers, especially one that isn’t controlled by a big company like Google or Microsoft.

Another cool thing is that Mozilla developed a language called Rust that some of the new parts of Firefox use. It’s a pretty interesting language – almost as fast as C, but more modern and supposedly it’s possible to write provably concurrency-safe code. I’m reading through the Rust book slowly…

Anyway, ThumbnailCopy is back!

Floating Point to Hex update, and writing tests as a sign of maturity

Over the weekend I published an update to my Floating Point to Hex calculator that allows you to swap the endianness of the hex bytes! Pretty exciting, no? (the answer is: meh)

It was actually more work than it looks like, because I decided to go ahead and update the backing script to Python 3, which meant I had to recompile the C module it uses. When I was about to start doing this I was disappointed to see that I didn’t have any tests in the project, so I went ahead and wrote those before changing everything. And even before I started changing things I found a few bugs (oh negative zero, you are tricky), so it was time well-spent!

I did have to refactor a few things to make the script testable, but I can’t imagine doing a refactor with only the help of spot-checking things, which is what I used to do. Just like writing clean code, writing tests is useful for future you as well as others!

Airport Guides is now available for Android!

I’m happy to announce that Airport Guides (now with terminal maps for over 90 airports worldwide) is now available as a free app for Android! (the Windows 10 version is still available, too!)

Now that Xamarin is included for free with Visual Studio, I thought it would be fun to try it out. Xamarin lets you make apps for Windows/Android/iOS by writing code in C#. Usually you have to then design your UI in the appropriate language (Java for Android, Objective-C/Swift for iOS), but with Xamarin.Forms you can even write a cross-platform UI in C#!

Since most of the work in the Airport Guides app is maintaining the maps themselves, the app is pretty small so I thought it would be a good candidate for porting as opposed to something like Bridge Scorer which has a ton of custom UI. The experience was pretty good – writing the UI in Xamarin.Forms is a lot like writing it in UWP for Windows 10, except all the keywords are different 🙂

I did run into some frustrations along the way. One was not realizing that you can’t test in-app purchase stuff without a real device. (although in retrospect the documentation does mention this…somehow I missed it) Another was that while the Android emulator for Visual Studio is literally 10x faster than the default emulator, there’s at least one bug that doesn’t show up in the real emulator. For the record, it was fetching a particular web page that would always timeout…I still never figured out why! Pinch/zoom was also tricky to get working until someone pointed me to MR.Gestures (which I always pronounce “Mr. Gestures” in my head 🙂 ), but I still am disappointed that every platform doesn’t have an easy builtin way to make pinch/zoom on an image work. Shoutout to Alan Clark from Xamarin for helping me through some of these!