gpt4 book ai didi

android - 访问依赖于其他库的 Android 库的公共(public)资源会产生这些资源被标记为私有(private)的警告

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:05 25 4
gpt4 key购买 nike

我为 Android 创建了一个库,它本身依赖于 appcompatdesign支持图书馆。通过在我图书馆的 Public.xml 中放置一个虚拟资源,我已将我图书馆的所有资源标记为私有(private)。 :

<public name="string_res_that_does_not_exist" type="string"/>

当我将我的库导入另一个项目时,Android Studio 在使用来自 appcompat 的公共(public)资源的行中生成警告和 design库,例如:

  • ?colorPrimary
  • ?colorPrimaryDark
  • ?colorAccent
  • ?selectableItemBackground

警告说 The resource @attr/<resource-name> is marked as private in <my-library-name> .

这个问题似乎与我的问题有关: https://code.google.com/p/android/issues/detail?id=183120

The root cause here is that when a library depends on another library, it imports all the resources from any libraries it depends on into its own declared R.txt (in the AAR file). However, it doesn't include the public.txt declaration from those dependencies, so now it ends up exposing these symbols as declared but not public -- e.g. private.

如何防止显示这些警告,以免我图书馆的其他用户遇到这些问题?

最佳答案

如果你想让 String 值对你的库项目私有(private),你可以做这样的事情:

例如:

// This annotation will restrict everything in this class to the library project.
@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class MyPrivateStrings
{
public static final String SUPER_SECRET_STRING = "I wet my pants in the 6th grade,"
+ "this information can’t escape the library!";

private MyPrivateStrings()
{

}
}

编辑:这可能不是 OP 正在寻找的确切答案,因为他们说他们将他们的 Strings 保留在他们的应用程序中资源目录但希望有人会发现这很有用,因为它是这里主要问题的可行解决方案。

关于android - 访问依赖于其他库的 Android 库的公共(public)资源会产生这些资源被标记为私有(private)的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com