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

查看:32
本文介绍了如何将 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. 遵循 Chris Banes 的说明(并在 this StackOverflow answer) 创建一个res-public/values/public.xml 文件夹也不起作用;所有的资源是私有的,但那些列在 public.xml文件未按应公开的方式公开.
  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

推荐答案

选项 #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天全站免登陆