Android APK Expansion Files - How to Address this Error

I was playing with trying to get the Android APK expansion file stuff to work, following the instructions from Google (and the accompanying sample project, which is a great resource and can save you a lot of time), and was getting a newbie-type error every time it tried to start my subclass of the com.google.android.vending.expansion.downloader.impl.DownloaderService class.  In particular, the error message would be something like this

W/ActivityManager(75): Unable to start service Intent { cmp=bfl.downloader/.MyDownloaderService (has extras) }: not found

I say "newbie" error because this is one of the most common errors for anyone first starting to use Android services, and can be caused by not putting the <service> element in the right place in the Android manifest file, the wrong classname, etc.

I was going crazy trying to figure this out, convinced I was still doing something silly.  Well, it turns out it wasn't me after all in this case.  There is apparently a problem with the DownloaderService class provided with the Android Google Downloader library, and this only reveals itself when you put your service class in a package other than that of the app... which I had done as a code-organization step.

There seem to be at least two ways to deal with this issue

(1) Make sure your subclass of DownloaderService is in the same package as the app

(2) Modify startDownloadServiceIfRequired in the class DownloaderService class
  • Existing line : String packageName =  serviceClass.getPackage().getName();  
  • Change to: String packageName =  context.getPackageName();
If you can live with your helper class being in the same package as the app, then no changes to the core library are required, and this definitely works (I'm watching it work with a test app as I type this).  As for the suggested change (2), it might have problems in other cases as well, and you'd need to keep your special version of the library updated against changes that Google might make to it.

Popular Posts