简体   繁体   English

在AAR文件中包含任意文件

[英]Include arbitrary files in AAR file

Is there a way to include a directory containing arbitrary files inside an AAR? 有没有办法在AAR中包含包含任意文件的目录? I'm using Android Studio + gradle. 我正在使用Android Studio + Gradle。

These are not source code files or anything, but binary files. 这些不是源代码文件或任何东西,而是二进制文件。

Yes, there is. 就在这里。

You can create an entire directory hierarchy in the assets directory. 您可以在assets目录中创建整个目录层次结构。 Here's an example: 这是一个例子:

src
    main
        assets
            foo
                bar.txt (file)
                foo2
                    baz.bin (file)

Your assets will be packed into the AAR automatically. 您的资产将自动打包到AAR中。

With a context, you can access these files in the application that links to your AAR like this: 通过上下文,您可以在链接到AAR的应用程序中访问这些文件,如下所示:

InputStream barIs = getAssets().open("foo/bar.txt");
InputStream bazIs = getAssets().open("foo/foo2/baz.bin");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM