Search code examples
androidandroid-studioandroid-gradle-pluginandroid-resourcesandroid-library

How to make Android library resources private?


How do I make the resources (string, dimen, color, etc.) in my Android library module private?

I've tried both documented ways of doing this and neither work...

  1. Following the official Android doc of creating a res/values/public.xml does not work; all of the resources remain public in the app that uses this library.
  2. Following Chris Banes's instruction (and reiterated in this StackOverflow answer) of creating a res-public/values/public.xml folder does not work either; all of the resources are made private, but those listed in the public.xml file are not made public as they should be.

Does anyone have the definitive instructions for making library resources private? Are there any open-source libraries out there that have properly made their resources private?

I'm using...

  • Android Studio v2.2.3
  • buildToolsVersion "24.0.2"
  • com.android.tools.build:gradle:2.2.3

Solution

  • Option #2 actually works. I had not properly defined my sourceSets in my build.gradle...

    sourceSets {
        main.res.srcDirs = [
            'src/main/res',
            'src/main/res-public'
        ]
    }