Author is a professional software developer providing android and iOS development services. More info here.
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
if-elseblocks. Switch can not be used in an android library with values like
R.id.xxxThese ints are
finalin 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=”http://schemas.android.com/apk/res/your_app_package_name” 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=”http://schemas.android.com/apk/res-auto” and this acts like a placeholder for the package name of the app using this library.
- If you are using
Applicationobject, 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.