Nemanja Kovacevic
Published in

Nemanja Kovacevic

Converting an android app to a library

Are you trying to convert your android app to library? It’s very simple, just go, Properties->Android, thick Is Library and that’s it. At least in theory, but here are couple of advices to make it work in real life as well…

  • Replace all switch blocks with if-else blocks. Switch can not be used in an android library with values like These ints are final in an android app project but they can not be in a library I guess since app can override them.
  • If you are rolling your own custom views with custom xml attributes you’ll get a “No resource identifier found for attribute” error for each one. When you add this kind of elements in your layout files you must off course define xml namespace for environment to find attributes specifications. Usually that looks something like xmlns:custom=”" Problem is that your_app_package_name is not the real package name anymore since this is a library. You can not set here a real package name for obvious reasons :). The solution is to put xmlns:custom=”" and this acts like a placeholder for the package name of the app using this library.
  • If you are using Application object, that code will be dead unless you reference it from the manifest of the app using the library.

There is an interesting use case for doing this. You’ve made an app but now you want to publish branded versions — “X app”, “Y app” with the same codebase but with branded UI. The easisest way to do this is to convert original project to thel ibrary and the reference it from the brand projects. More about this in one of the next posts.



Software engineer specialized in creating native android and iOS apps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store