Google Play Store – Can’t install app (Error code: -504)
I’ve stumbled upon this issue straight after I released my app into the store…
I did a brief search on the Internet what could be causing such behaviour and majority of posts were pointing at some issues with cached data by Google Play Store and/or Google Play Services somehow breaking installation process. They were suggesting cleaning cache of these to solve the problem. Combination of clearing cached data, uninstalling the app, restarting the device and even ejecting the SD card did not help
I didn’t give up though. I was fortunate enough to have a device at home, that I was able to reproduce this with. At least it was showing some errors when trying to deploy and debug the app using Visual Studio – which was a good start. Each and every time I tried to deploy the app onto the device I was getting the error
ADB0010: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1021324914.tmp/base.apk (at Binary XML file line #28): does not have valid android:name]
It didn’t tell me much, so I started googling it. Some of the StackOverflow posts (#1, #2) that I found were pointing me at the problem with package name capital letters. Yep, I did put some capital letters in my app name (i.e. com.progrunning.AirQuality, which ultimately became com.progrunning.airquality). I changed the name of the app in the AndroidManifest.xml but I was still getting that error…
I had no choice but to check what’s actually being generated/added by Xamarin.Forms into the AndroidManifest.xml when packaging the app. I went to my bin\Debug folder, to try to unzip the generated *.apk file – *.apk is just fancy *.zip file that contains your application, dll's, configuration, assets etc.. Unfortunately, at this stage the AndroidManifest.xml file in the *.apk is nothing but binary data. Which looks something like this when opened with Visual Studio Code:
Fortunately, thanks to this StackOverflow answer, I learned that there’s a way of reading what's in the *.apk package. I located the aapt.exe file, where my android sdk got installed (in my case it was C:\Programming\SDK\Android\android-sdk\build-tools\27.0.3) and ran the command
aapt.exe l -a “C:\Programming\Projects\Own\AirQuality\AirQuality\AirQuality.Android\bin\Debug\com.progrunning.airquality.apk”
The above prints out quite a bit of stuff (you can probably narrow it with some pipes and grep commands – I'm no expert on these though), but we're interested only in the AndroidManifest.xml file. From the error that I got when trying to deploy and debug the app I knew that something that prevents this from happening is located at the line 28. Browsing through the results I finally stumbled onto the below, what turned out to be an answer to the issue:
Turns out the problem was, that I used capital letters for my background service (biiiiiiiiiiiiig mistake!):
Changing the name of that background service to lowercase fixed the problem.
EDIT: The problem didn't seem to be happening on the Android versions 8.0+. It was only affecting 6.0 and 7.0 (maybe more but these two versions are definitely confirmed)
EDIT2: I ended up with my app name having capital letters in it – that was not the problem