Where do I place the 'assets' folder in Android Studio?

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.

How can the Assets directory be configured in Android Studio?


Since Android Studio uses the new Gradle-based build system, you should be putting assets/ inside of the source sets (eg, 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:

  • 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/ )

  • Your product flavors can also have sourcesets with assets (eg, 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

  • Also, a quick reminder: assets are read-only at runtime. Use internal storage, external storage, or the Storage Access Framework for read/write content.


    Let Android Studio do it for you.

  • In Android Studio (1.0 & above), right-click on the folder and navigate to the Assets Folder .
  • 在这里输入图像描述

  • On the next screen just click Finish .
  • 在这里输入图像描述

    And voila! It will create the assets folder in the main target source set.


    Looking inside the .iml file of your project you will see the following line:

     <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
    

    This means the "assets" folder is already declared for Gradle. You will need to create it under src/main/ (I'm using Android Studio 0.4.2).

    链接地址: http://www.djcxy.com/p/74928.html

    上一篇: Android中的默认字体系列是什么?

    下一篇: 我在哪里可以将“assets”文件夹放在Android Studio中?