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

kalehv 08/13/2017. 14 answers, 369.419 views
android android android-studio android-studio android-assets

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?

14 Answers


CommonsWare 09/15/2016.

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

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 (e.g,. app/src/release/assets/)

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

  • 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.

5 comments
1 kalehv 08/18/2013
I am trying to include a custom font in the assets directory. Should I be good to go by just pasting the .ttf file as src/main/assets/font.ttf ? or do i need to assign the font explicitly by code to the control to see it?
3 CommonsWare 08/18/2013
@kalehv: "or do i need to assign the font explicitly by code to the control to see it?" -- oh, absolutely. You will need to call setTypeface() on all TextView widgets (and others that inherit from TextView) that you want to use this particular font.
12 kalehv 08/18/2013
Cool. That worked like a charm. I wish there was a way to include Assets font (custom) into Styles.xml rather than using it through code. (My wish might sound too dumb to handle, I am a beginner so excuse me if it is :-P)
1 srowley 01/10/2015
Thank you! I've been searching for hours for this. I tried creating a sub directory for assets under /src/main/res/ and the directory was being removed from the apk build.
2 CommonsWare 08/16/2016
@Bora: Then you do not have countries.txt in the assets/ directory. Here is a sample project that, among other things, copies a file from assets into internal storage. If you have further concerns, please ask a separate Stack Overflow question, where you provide a Minimal, Complete, and Verifiable example.

Prince 05/22/2015.

Let Android Studio do it for you.

  1. In Android Studio (1.0 & above), right-click on the enter image description here folder and navigate to the Assets Folder.

enter image description here

  1. On the next screen just click Finish.

enter image description here

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

enter image description here

5 comments
68 Tan Jit Ren 01/15/2015
this solution is for Android Studio 1.0 and above. Other answers are obsolete.
16 fullMoon 10/02/2015
Graphical illustration makes all the difference in the world!
1 Scott Biggs 06/27/2016
Problem: on newer versions of Android Studio (I'm using 2.1.2), empty asset folders are not displayed in the Project Files window, making it difficult to add files. :(
1 Prince 06/28/2016
@ScottBiggs Once you add the assets folder as shown above (on v2.1.2), it should be visible inside app > src > main
1 VeeK 05/19/2017
What would be the link to this folder in a java file?

Miguel El Merendero 01/21/2017.

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).

4 comments
8 nitsujri 03/13/2014
My .iml doesn't have this, what portion of the file do I add this to?
11 fernandohur 06/05/2014
you probably have 2 .iml files, check both of them.
1 Tony 08/18/2015
check app.iml not <Project-Name>.iml
1 Sindri Þór 09/20/2015
Allways in .im at root of you src.. not in the project directory.. Thats just for gradle stuff.

Jorgesys 08/10/2017.

Select the app folder and then:

File > New > folder > assets Folder ,

enter image description here

the default location is inside /main folder

enter image description here


Pankaj kumar 07/27/2015.

Simple follow this

File > New > folder > assets Folder

Note : App must be selected before creating folder.


Sportman Appman 12/11/2014.

In android studio you can specify where the source, res, assets folders are located. for each module/app in the build.gradle file you can add something like:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    sourceSets {
        main {
            java.srcDirs = ['src']
            assets.srcDirs = ['assets']
            res.srcDirs = ['res']
            manifest.srcFile 'AndroidManifest.xml'
        }
    }
}
1 comments
Hajder Rabiee 10/27/2015
is this necessary if one follows the convention?

zizoujab 06/22/2015.

If you tried all your bullets in this thread in vain try cleaning your project . In my case it only worked after Projet -> clean

1 comments
1 ssimm 03/10/2016
This is more like a comment than an answer, but it saved me so +1

Shraddha Patel 02/15/2017.

right click on app folder->new->folder->Assets folder->set Target Source set->click on finish button

1 comments
pkpdeveloper 06/02/2017
it works,thanks

stkent 05/23/2017.

When upgrading to the release version of Android Studio, you may be automatically switched to the new Android project View (see here for more info). If you swap back to either the Project or Packages view, you should see the standard folder hierarchy of a gradle-based project. Then refer to CommonsWare's answer for the appropriate location.


madjardi 02/18/2016.

need configure parameter for gradle
i hope is will work

// file: build.gradle  
sourceSets {
    main {
        assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
    }
}

Pablo Cegarra 01/21/2017.

Click over main → new directory → directory name "assets"


HEISENBERGG 05/20/2017.

Put the assets folder in the main/src/assets.


A. Nutley 07/26/2017.
Src/main/Assets

It mightnt show on you side bar if app is selected. Click the drop down at the top that says android and select packages. you will see it then.


Dharmendra Pratap 01/21/2017.

In Android Studio, click on the app folder, then the src folder, and then the main folder. Inside the main folder you can add the assets folder.

3 comments
3 Gaurav Dave 05/20/2016
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
1 Dharmendra Pratap 05/20/2016
In Android Studio click on app folder, then src folder, then main folder . Inside main folder you can add Assets folder.
1 Gaurav Dave 05/20/2016
Don't add in the comment, use edit link and update your answer

HighResolutionMusic.com - Download Hi-Res Songs

1 (G)I-DLE

POP/STARS flac

(G)I-DLE. 2018. Writer: Riot Music Team;Harloe.
2 The Chainsmokers

Beach House flac

The Chainsmokers. 2018. Writer: Andrew Taggart.
3 Ariana Grande

​Thank U, Next flac

Ariana Grande. 2018. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.
4 Nicki Minaj

No Candle No Light flac

Nicki Minaj. 2018. Writer: Denisia “Blu June” Andrews;Kathryn Ostenberg;Brittany "Chi" Coney;Brian Lee;TJ Routon;Tushar Apte;ZAYN;Nicki Minaj.
5 Clean Bandit

Baby flac

Clean Bandit. 2018. Writer: Jack Patterson;Kamille;Jason Evigan;Matthew Knott;Marina;Luis Fonsi.
6 Imagine Dragons

Bad Liar flac

Imagine Dragons. 2018. Writer: Jorgen Odegard;Daniel Platzman;Ben McKee;Wayne Sermon;Aja Volkman;Dan Reynolds.
7 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
8 BTS

Waste It On Me flac

BTS. 2018. Writer: Steve Aoki;Jeff Halavacs;Ryan Ogren;Michael Gazzo;Nate Cyphert;Sean Foreman;RM.
9 BlackPink

Kiss And Make Up flac

BlackPink. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
10 Fitz And The Tantrums

HandClap flac

Fitz And The Tantrums. 2017. Writer: Fitz And The Tantrums;Eric Frederic;Sam Hollander.
11 Backstreet Boys

Chances flac

Backstreet Boys. 2018.
12 Kelly Clarkson

Never Enough flac

Kelly Clarkson. 2018. Writer: Benj Pasek;Justin Paul.
13 Diplo

Close To Me flac

Diplo. 2018. Writer: Ellie Goulding;Savan Kotecha;Peter Svensson;Ilya;Swae Lee;Diplo.
14 Anne-Marie

Rewrite The Stars flac

Anne-Marie. 2018. Writer: Benj Pasek;Justin Paul.
15 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
16 Imagine Dragons

Machine flac

Imagine Dragons. 2018. Writer: Wayne Sermon;Daniel Platzman;Dan Reynolds;Ben McKee;Alex Da Kid.
17 Little Mix

The Cure flac

Little Mix. 2018.
18 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
19 Rita Ora

Velvet Rope flac

Rita Ora. 2018.
20 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.

Related questions

Hot questions

Language

Popular Tags