If you are building an SDK with android resources like layouts and drawable, then your choice will be an aar file.

Dealing with Permission !!

You shouldn’t add any dangerous permissions directly in the SDK manifest, instead specify them in the SDK document, why you need that, let the developer make a choice based on their needs. if the client app didn’t add the permission required for the SDK, gracefully disable that functionality.

If you add permission in the SDK’s manifest file, androidManifestMerger combines SDK manifest + client application manifest to a single one. This way you can avoid dangerous permissions sneaks into the client app.

Android Manifest Merger View

Making Resource public or private ?

All resources in a library default to public. To prevent users of your library from accessing resources intended only for internal use, you should use automatic private designation mechanism by declaring one or more public resources. To make all resources implicitly private, you must define at least one specific attribute as public. To make all resources private simply add <public /> to any of your existing resource files. When building a library, the Android Gradle plugin gets the public resource definitions and extracts them into the public.txt file, which is then packaged inside the AAR file.

Handling dependencies

aar can have multiple dependencies. But when you ship your SDK as aar, those dependencies won’t be bundled with SDK. Strange right ??. This is because aar doesn’t have any POM file to download the dependencies.

How to solve this?

Specify the same required dependencies in the client app. (Mention the dependencies in the SDK doc that you ship with SDK) or you can host the SDK in the repository like Maven()/Jcenter(). That repository supports the POM file, which takes care of downloading SDK dependencies.

Check the POM file of Retrofit

If you want to host the artifact internally like private Repo, check this cool tutorial.

Prune/trim your SDK

Always keep an eye on the method count. Think twice before you add a dependency. If you badly need it, take out things which you don’t need from the external libraries. I had used below tools for keeping my dex count to a minimum.

Proguard your code the very first day

Don’t keep it for last, I know optimizing and playing around with proguard is hard. But if you start from the day one, you won’t be stressed during the release. You can refer to these sample rules for the commonly used android libraries.

Theme documentation

If your SDK contains layouts that ultimately hosted in the Activity/Fragment. But you want to give the developer an option to customize the color/font/size of widgets in the layout !! How you will do that ??

AAPT(Android asset packaging tool) will help you on this. AAPT remove the redundant resources, means if you have the same resource in the SDK and client app, client app will take the priority over the SDK.

Let’s say if you want to change the Toolbar layout background color in the SDK, override the same resource name in the client app and change the color. That’s it !!

The only thing you need to expose is that a theme document mentioning which theme is applied to the widget. They can keep the same name and change the values of the attributes.

Thanks!!

¯\_(ツ)_/¯