Android 库 (aar) 的 assets/ 目录中的资产

Assets in assets/ directory for Android library (aar)

基于Android Library Considerations

Library modules cannot include raw assets

我创建了一个示例 android 库模块,其中包含资产(不在应用程序模块中),然后生成了 aar 文件。我分析了生成的 aar 文件,瞧,资产/文件夹仍然存在,所有文件都完好无损。

那么,允许还是不允许?

我认为某些开发注意事项已经过时了。例如,他们还说 <uses-library> 元素必须在库和应用程序中声明(现在由清单合并处理)。

顺便说一下下面的几行,A​​AR 文件剖析 表明 AAR 文件可能包含 /assets/ 目录

这里有一些关于这个主题的有趣帖子:

how to reference an asset in a library project

Android Library assets folder doesn't get copied

它只是说:库模块不能包含原始资产 它没有说 Library modules should not include raw assets 。也许在过去它不被支持。现在上面的帖子和他们的回答表明它是支持的。

android 库中不允许文件夹 assets/。您可以从 res/raw 访问它 使用以下代码。

context.getResources().openRawResource(R.raw.file_name);

我在 Android Library Considerations: with Google on May 7, 2018 issuetracker 79311037.

中提出了这个 文档问题

正在处理中,这是最新评论(Jul 14, 2018):

As well as being wrong, the documentation also contradicts itself, as the "Anatomy of an AAR file" section at the bottom does include an assets directory.