哪里将“资产"文件夹放在Android Studio中? [英] Where to place the 'assets' folder in Android Studio?
问题描述
我对assets
文件夹感到困惑.它不是在Android Studio中自动创建的,讨论该问题的几乎所有论坛都在谈论Eclipse.
I am confused about the assets
folder. It doesn't come auto-created in Android Studio, and almost all the forums in which this is discussed talk about Eclipse.
如何在Android Studio中配置Assets目录?
How can the Assets directory be configured in Android Studio?
推荐答案
由于Android Studio使用新的基于Gradle的构建系统,您应该是
Since Android Studio uses the new Gradle-based build system, you should be putting assets/
inside of the source sets (e.g., src/main/assets/
).
在典型的Android Studio项目中,您将具有一个app/
模块,该模块具有一个main/
源集(项目根之外的app/src/main/
),因此您的主要资产将放入app/src/main/assets/
中.但是:
In a typical Android Studio project, you will have an app/
module, with a main/
sourceset (app/src/main/
off of the project root), and so your primary assets would go in app/src/main/assets/
. However:
-
如果您需要特定于构建类型的资产,例如
debug
与release
,则可以为这些角色创建源集(例如app/src/release/assets/
)
If you need assets specific to a build type, such as
debug
versusrelease
, you can create sourcesets for those roles (e.g,.app/src/release/assets/
)
您的产品风味还可以包含带有资产的来源集(例如app/src/googleplay/assets/
)
Your product flavors can also have sourcesets with assets (e.g., app/src/googleplay/assets/
)
您的仪器测试可以具有带有自定义资产(例如,app/src/androidTest/assets/
)的androidTest
源集,尽管一定要向InstrumentationRegistry
询问getContext()
,而不是getTargetContext()
,以访问这些资产
Your instrumentation tests can have an androidTest
sourceset with custom assets (e.g., app/src/androidTest/assets/
), though be sure to ask the InstrumentationRegistry
for getContext()
, not getTargetContext()
, to access those assets
还要提醒一下:资产在运行时是只读的.使用内部存储,用于读取/写入内容的存储访问框架.
Also, a quick reminder: assets are read-only at runtime. Use internal storage, external storage, or the Storage Access Framework for read/write content.
这篇关于哪里将“资产"文件夹放在Android Studio中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!