如何在库项目中引用资产 [英] how to reference an asset in a library project
问题描述
在属于我调用的图书馆项目的类中:
In a class belonging to a Library project I call:
webview.loadUrl("file:///android_asset/info.html", null);
不幸的是,这仅在我复制文件 info.html 到应用程序的项目资产文件夹中时才有效.
Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.
有没有办法告诉 Android 库代码:在库的资产文件夹中查找此文件,不是在应用程序的资产文件夹中"?
Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?
推荐答案
这个答案是过时,gradle 构建系统和 AAR 文件支持资产.
<小时>来自 Android 文档:
This answer is out of date, the gradle build system and AAR files support assets.
From the Android Docs:
图书馆项目不能包含原始资产
这些工具不支持在库项目中使用原始资产文件(保存在 assets/目录中).应用程序使用的任何资产资源都必须存储在应用程序项目本身的 assets/目录中.但是支持res/目录下的资源文件.
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
如果您想包含库项目中的文件,您需要将它放在资源中而不是资产中.如果您尝试将库项目中的 HTML 文件加载到 WebView 中,这意味着您必须采用比通常的资产 URL 更迂回的方法.相反,您必须读取资源数据并使用类似 loadData.
If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.
这篇关于如何在库项目中引用资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!