1576

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?

Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
Harshad Kale
  • 17,446
  • 7
  • 30
  • 44

26 Answers26

1815

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 type, 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. (note: the first two links are to my blog)

Ryan M
  • 18,333
  • 31
  • 67
  • 74
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    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? – Harshad Kale Aug 18 '13 at 19:06
  • 3
    @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. – CommonsWare Aug 18 '13 at 19:10
  • 17
    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) – Harshad Kale Aug 18 '13 at 19:17
  • 1
    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. – srowley Jan 10 '15 at 06:33
  • Jeez. The android documentation needs to be way more explicit about this kind of stuff. This was unnecessarily hard to find. – Ray Kiddy Sep 01 '15 at 23:13
  • how to read a file once assets folder is created . InputStream stream = getApplicationContext().getResources().getAssets().open("countries.txt"); It gives me filenotfound excepton – Bora Aug 16 '16 at 10:41
  • 2
    @Bora: Then you do not have `countries.txt` in the `assets/` directory. [Here is a sample project](https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/V4FileProvider) 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 [mcve]. – CommonsWare Aug 16 '16 at 10:59
  • This answer is no longer exactly accurate, as the way Android Studio renders the file structure has changed. – mavrosxristoforos Oct 26 '16 at 16:28
  • @mavrosxristoforos: No, this answer is still accurate, as I am referring to the filesystem (in Android Studio, you get a filesystem view through the Project rendition of the explorer tree). – CommonsWare Oct 26 '16 at 16:44
  • @CommonsWare Yes, I agree. However, running under a completely default Android Studio 2.2.2, you don't get the exact File Structure on the Project navigator. That's what I intended to point out. – mavrosxristoforos Oct 26 '16 at 16:56
  • On newer versions of Android Studio, there is no more src folder, see below answer for Android Studio to create it for you automatically. – Larry Jing Jun 13 '18 at 17:17
  • @LarryJing: There is a `src` folder in any standard Android Studio project, including those created in Android Studio 3.1.2 and the current canary release of 3.2. – CommonsWare Jun 13 '18 at 22:29
1619

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

Prince
  • 20,353
  • 6
  • 39
  • 59
  • 105
    this solution is for Android Studio 1.0 and above. Other answers are obsolete. – JR Tan Jan 15 '15 at 04:50
  • 53
    Graphical illustration makes all the difference in the world! – fullmoon Oct 02 '15 at 18:02
  • 2
    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. :( – SMBiggs Jun 27 '16 at 15:40
  • 2
    @ScottBiggs Once you add the _assets_ folder as shown above (on v2.1.2), it should be visible inside _app > src > main_ – Prince Jun 28 '16 at 05:23
  • 2
    What would be the link to this folder in a java file? – Whip May 19 '17 at 05:05
  • @VeeK For e.g. if you need to access `assets>fonts` you would do something like: `Typeface t = Typeface.createFromAsset(getAssets(),"font/myfont.ttf"));` So a call to `getAssets()` will give you path to directories inside `assets` folder. – Prince Sep 04 '20 at 14:37
129

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Miguel El Merendero
  • 2,054
  • 1
  • 17
  • 17
94

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

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
65

First of all the "Assets" folder will not be created automatically with the project. We have to create it.

The location of Assets folder is: App > src > Assets

Please have a look of the simple image below.

enter image description here

Note: For creating assets folder just click on Project => Right click => Select New => Folder => Assets. It will create Assets folder.

Arun J
  • 687
  • 4
  • 14
  • 27
Lovekush Vishwakarma
  • 3,035
  • 23
  • 25
  • If another newbie was confused by all these answers like me, the folder structure can look different based on the selection in the top left corner. Mine was "Android" while all the people here are using "Project" or "Project Files". – Big_Chair Apr 22 '19 at 10:04
  • project structure is different based on what you select for Project structure, project, project files, packages, Android etc, but you follow the screens what I share and see the selection of project structure type. – Lovekush Vishwakarma Apr 24 '19 at 13:26
43

It's simple, follow these steps

File > New > Folder > Assets Folder

Note : App must be selected before creating folder.

Arun J
  • 687
  • 4
  • 14
  • 27
Pankaj kumar
  • 1,357
  • 14
  • 13
31

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'
        }
    }
}
Sportman Appman
  • 311
  • 3
  • 2
28

Simply, double shift then type Assets Folder

choose it to be created in the correct place

Mohammad Alotol
  • 1,409
  • 15
  • 23
22

Click over main → new -> directory → and type as name "assets"

or... main -> new -> folder -> assets folder (see image)

enter image description here

Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110
20

In Android Studio 4.1.1

Right Click on your module (app for example) -> New -> Folder -> Assets Folder

enter image description here

AmrDeveloper
  • 3,826
  • 1
  • 21
  • 30
17

Project -> app -> src -> main -> RMB(right mouse button) -> New -> Directory:

enter image description here

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
16

File > New > folder > assets Folder

Assets Folder

Gowtham Subramaniam
  • 3,358
  • 2
  • 19
  • 31
13

Two ways:

  1. Select app/main folder, Right click and select New => Folder => Asset Folder. It will create 'assets' directory in main.

  2. Select main folder, Right click and select New => Directory Enter name as 'assets' = > Ok.

enter image description here

Arun J
  • 687
  • 4
  • 14
  • 27
TejpalBh
  • 427
  • 4
  • 13
12

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

zizoujab
  • 7,603
  • 8
  • 41
  • 72
12

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

Shraddha Patel
  • 149
  • 1
  • 5
9

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

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59
8
Src/main/Assets

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

winchester100
  • 147
  • 3
  • 13
S.Doyle
  • 215
  • 3
  • 17
7

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.

stkent
  • 19,772
  • 14
  • 85
  • 111
7

need configure parameter for gradle
i hope is will work

// file: build.gradle  
sourceSets {
    main {
        assets.srcDirs = ['src/main/res/icon/', 'src/main/assets/']
    }
}
madjardi
  • 5,649
  • 2
  • 37
  • 37
6

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 3
    This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/12416138) – Gaurav Dave May 20 '16 at 09:58
  • 2
    In Android Studio click on app folder, then src folder, then main folder . Inside main folder you can add Assets folder. – Dharmendra Pratap May 20 '16 at 13:29
5

Step 1 : Go to Files. Step 2 : Go to Folders. Step 3 : Create Assets Folder.

In Assets folder just put fonts and use it if needed.

Deep Adhia
  • 382
  • 4
  • 11
5
follow these steps 

1)file->New->Folder
 there are multiple options like
      aidl folder
      assets folder
      jni folder
2) choose options assets folder
3) then there is option to change path of assets folder if you 
    want to change then check otherwise left that checkbox of cahnge folder location
4) click on finish 
indrajeet jyoti
  • 431
  • 6
  • 8
4

Either create a directory under /app/src/main or use studio File-> New -> Folder - > Assets Folder.

Durgesh
  • 101
  • 7
3

In Android Studio right-click Folder in app->src->main then create new DIRECTORY name that assets.

1

It seems that nobody mentioned this:
You can define it in Project Structure > Project Settings:

enter image description here

Shamshirsaz.Navid
  • 2,224
  • 3
  • 22
  • 36
0

You easily adding an assets folder using Android Studio like this:

enter image description here

ahmnouira
  • 1,607
  • 13
  • 8