Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

android-studio - 如何在Android Studio中将“资产”文件夹放在哪里?(Where do I place the 'assets' folder in Android Studio?)

I am confused about the assets folder.

(我对assets文件夹感到困惑。)

It doesn't come auto-created in Android Studio, and almost all the forums in which this is discussed talk about Eclipse.

(它不是在Android Studio中自动创建的,讨论该主题的几乎所有论坛都谈论Eclipse。)

How can the Assets directory be configured in Android Studio?

(如何在Android Studio中配置Assets目录?)

  ask by kalehv translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since Android Studio uses the new Gradle-based build system , you should be putting assets/ inside of the source sets (eg, src/main/assets/ ).

(由于Android Studio使用新的基于Gradle的构建系统 ,因此您应将assets/放在源集中 (例如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/ .

(在一个典型的Android Studio项目中,您将有一个app/模块,具有一个main/源码集( app/src/main/在项目根目录之外),因此您的主要资产将进入app/src/main/assets/ 。)

However:

(然而:)

  • If you need assets specific to a build, such as debug versus release , you can create sourcesets for those roles (eg,. app/src/release/assets/ )

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

  • Your product flavors can also have sourcesets with assets (eg, app/src/googleplay/assets/ )

    (您的产品口味还可以包含带有资产的资源集(例如app/src/googleplay/assets/ ))

  • Your instrumentation tests can have an androidTest sourceset with custom assets (eg, app/src/androidTest/assets/ ), though be sure to ask the InstrumentationRegistry for getContext() , not getTargetContext() , to access those assets

    (您的检测测试可以具有带有自定义资产的androidTest (例如app/src/androidTest/assets/ ),尽管一定要向InstrumentationRegistry请求getContext()而不是getTargetContext()来访问这些资产)

Also, a quick reminder: assets are read-only at runtime.

(另外,还有一个简短的提醒:资产在运行时是只读的。)

Use internal storage , external storage , or the Storage Access Framework for read/write content.

(使用内部存储外部存储Storage Access Framework读取/写入内容。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...