Difference Between /Res and /Assets Directories

Difference between /res and /assets directories

With resources, there's built-in support for providing alternatives for different languages, OS versions, screen orientations, etc., as described here. None of that is available with assets. Also, many parts of the API support the use of resource identifiers. Finally, the names of the resources are turned into constant field names that are checked at compile time, so there's less of an opportunity for mismatches between the code and the resources themselves. None of that applies to assets.

So why have an assets folder at all? If you want to compute the asset you want to use at run time, it's pretty easy. With resources, you would have to declare a list of all the resource IDs that might be used and compute an index into the the list. (This is kind of awkward and introduces opportunities for error if the set of resources changes in the development cycle.) (EDIT: you can retrieve a resource ID by name using getIdentifier, but this loses the benefits of compile-time checking.) Assets can also be organized into a folder hierarchy, which is not supported by resources. It's a different way of managing data. Although resources cover most of the cases, assets have their occasional use.

One other difference: resources defined in a library project are automatically imported to application projects that depend on the library. For assets, that doesn't happen; asset files must be present in the assets directory of the application project(s). [EDIT: With Android's new Gradle-based build system (used with Android Studio), this is no longer true. Asset directories for library projects are packaged into the .aar files, so assets defined in library projects are merged into application projects (so they do not have to be present in the application's /assets directory if they are in a referenced library).]

EDIT: Yet another difference arises if you want to package a custom font with your app. There are API calls to create a Typeface from a font file stored in the file system or in your app's assets/ directory. But there is no API to create a Typeface from a font file stored in the res/ directory (or from an InputStream, which would allow use of the res/ directory). [NOTE: With Android O (now available in alpha preview) you will be able to include custom fonts as resources. See the description here of this long-overdue feature. However, as long as your minimum API level is 25 or less, you'll have to stick with packaging custom fonts as assets rather than as resources.]

difference between assets folder and res/xml

The res folder is used to put authorized resources files type, like layout(xml), drawable (png, jpg, xml), raw (mp3, ogg), etc... In the assets folder, you can put all files types you want (txt, avi, png, docx, xyz, ext, asm, ....).

Check this : Android Projects Structure

1) assets/

This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

2) res/

Contains application resources, such as drawable files, layout files, and string values. See Application Resources for more information.

  • anim/

For XML files that are compiled into animation objects. See the Animation resource type.

  • color/

For XML files that describe colors. See the Color Values resource type.

  • drawable/

For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.

  • layout/

XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.

  • menu/

For XML files that define application menus. See the Menus resource type.

  • raw/

For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.

  • values/

For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.

  • xml/

For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata. See Application Resources for more information about configuring these application components.

Difference between res/ and resources/

The test folder contains code (usually test code, unit tests, etc...) that runs on your local PC or laptop. The code compiled and eventually run using the installed Java on your machine the same way as pure Java projects with some minor differences. So basically the purpose of the test folder is to test parts of application code that don't have a dependency on the Android SDK and without using an Android device. Also on the side, there's another test folder which is androidTest, it also used for testing parts of the application but with using an Android device, meaning an actual test application is loaded on the device and it executes the tests which have a dependency on the Android SDK.

That being said, pure Java projects or code usually use resources folder and not res (as far I have seen while using IDEs). When compiling and then running the pure Java projects or code, the contents of the resources folder are placed at the root of the Java classpath so that the code being executed finds its resources there.

Android Studio or the Android Gradle Plugin seems to handle both differently (in terms of packaging them into the final aar or apk), so it is best that there is only res in main or androidTest folder and also that there is only resources in test folder.

When should I use the assets as opposed to raw resources in Android?

The main differences between the raw folder and the assets folder.

  • Since raw is a subfolder of Resources (res), Android will
    automatically generate an ID for any file located inside it. This
    ID is then stored in the R class that will act as a reference to
    a file, meaning it can be easily accessed from other Android classes
    and methods and even in Android XML files. Using the automatically
    generated ID is the fastest way to have access to a file in Android.

  • The assets folder is an “appendix” directory. The R class does
    not generate IDs
    for the files placed there, which is less compatible
    with some Android classes and methods. File access in the assets folder is slower since you will need to get a handle to it
    based on a String
    . However some operations are more easily done by
    placing files in this folder, like copying a database file to the
    system’s memory. There’s no (easy) way to create an Android XML
    reference to files inside the Assets folder.

Android, difference between assets folder and internal storage

Yes, your understanding is correct. The difference between the Assets folder and the Internal Storage folder is that the Assets folder can't be changed at runtime. So the usage of internal storage and assets folder is as follows-

1) When one has fixed content like fonts,images,styles,string values,etc. put it into the assets folder.

2) If based on the programme the values must change based on the situation then save those values in the Internal Storage.

Should an extra file be placed in raw or assets folder?

assets/ is flexible in terms of structure. You can have your own directory tree in there, for organizing lots of files.

res/raw/ is flexible in terms of resource sets. You can have different versions of that resource for different configurations (e.g., res/raw/ as the default, res/raw-zh/ for use on devices configured for Chinese language use).

If you do not need any of those features, assets/ and res/raw/ are about equal in terms of capability. I tend to default to assets/.

Android: When is it appropriate to store images in the assets rather than the drawable folders?


The difference between a raw resource in res/raw directory and an asset is that assets behave like a file system, they can be listed, iterated over, discovered, just like files while for raw resources, you need the resource ID.

From: http://mylifewithandroid.blogspot.it/2009/06/assets.html (emphasis mine)

Also you may use assets when you need to organize things using sub-folders.

Android Studio: Where do I have to put assets and res?

The assets and res folders should be in the same level as your java folder:

Sample Image



Related Topics



Leave a reply



Submit