访问依赖于其他库的 Android 库的公共资源会产生警告,指出这些资源被标记为私有

San*_*ell 5 android android-studio aar

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

<public name="string_res_that_does_not_exist" type="string"/>
Run Code Online (Sandbox Code Playgroud)

当我将我的库导入另一个项目时,Android Studio 会在使用appcompat和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

这里的根本原因是,当一个库依赖另一个库时,它会将其依赖的任何库中的所有资源导入到自己声明的 R.txt(在 AAR 文件中)中。但是,它不包括来自这些依赖项的 public.txt 声明,因此现在它最终将这些符号公开为已声明但不是公共的——例如私有的。

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

Sak*_*boy 0

如果您想让String值对您的图书馆项目私有,您可以执行以下操作:

\n\n

前任:

\n\n
// This annotation will restrict everything in this class to the library project.\n@RestrictTo(RestrictTo.Scope.LIBRARY)\npublic final class MyPrivateStrings\n{\n    public static final String SUPER_SECRET_STRING = "I wet my pants in the 6th grade,"\n                   + "this information can\xe2\x80\x99t escape the library!";\n\n    private MyPrivateStrings()\n    {\n\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n