Android Studio 中的“assets"文件夹放在哪里? [英] Where to place the 'assets' folder in Android Studio?

查看:61
本文介绍了Android Studio 中的“assets"文件夹放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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 的构建系统,你应该assets/ 放在源集内(例如,src/main/assets/).

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:

  • 如果您需要特定于构建类型的资产,例如 debugrelease,您可以为这些角色创建源集(例如,app/src/release/assets/)

  • If you need assets specific to a build type, such as debug versus release, 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/)

您的仪器测试可以有一个带有自定义资产的 androidTest 源集(例如,app/src/androidTest/assets/),但一定要询问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 中的“assets"文件夹放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆