如何将Android库资源设为私有? [英] How to make Android library resources private?

查看:126
本文介绍了如何将Android库资源设为私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Android库模块中的资源(字符串,尺寸,颜色等)设为私有?

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. 按照官方Android文档来创建 res/values/public.xml不起作用;所有资源仍然保留 在使用此库的应用中公开.
  2. 遵循克里斯·贝恩斯的说明(并在
  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?

我正在使用...

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

推荐答案

选项#2实际上有效.我没有在build.gradle中正确定义sourceSets ...

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'
    ]
}

这篇关于如何将Android库资源设为私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆