Where to place the 'assets' folder in Android Studio?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The assets folder in Android is used to store raw files that your application can read at runtime using the AssetManager API. Unlike the res directory, files in assets are not assigned resource IDs and can have arbitrary directory structures. Knowing where to place this folder and how to use it is essential for working with bundled files like HTML pages, JSON data, fonts, or databases.
Correct Location
In Android Studio, the assets folder belongs inside the main source set, at the same level as the java and res directories:
The full path is:
How to Create It
Method 1: Using Android Studio UI
- Right-click on the
appmodule in the Project panel - Select New > Folder > Assets Folder
- Keep the default location (
src/main/assets) and click Finish
Method 2: Manual Creation
Create the directory manually:
Android Studio will recognize it automatically on the next Gradle sync.
Method 3: Custom Location in build.gradle
You can specify a custom assets directory in your build.gradle:
Reading Files from Assets
Use the AssetManager to read files at runtime:
Java
Kotlin
Listing Files in a Subdirectory
Assets vs res/raw
Both assets and res/raw can store raw files, but they serve different purposes:
| Feature | assets/ | res/raw/ |
| Resource ID | No | Yes (R.raw.filename) |
| Subdirectories | Yes | No |
| File naming | Any characters | Lowercase, no special chars |
| Access method | AssetManager | Resources.openRawResource() |
| Included in APK | As-is | As-is |
| Use case | Complex file structures, web content | Simple files like audio, certificates |
Common Use Cases
Loading a Custom Font
Loading a Local HTML Page in WebView
Note the triple slash and android_asset (not assets) in the URL scheme.
Pre-populating a Room Database
Build Variants and Flavors
You can have different assets per build variant:
Assets from more specific source sets override those from main.
Common Pitfalls
- Case sensitivity: Asset file names are case-sensitive on Android.
Data.jsonanddata.jsonare different files. Be consistent with naming. - File size limits: While there is no hard limit on individual asset files, very large files (>100MB) may cause build issues or slow app startup. Consider downloading large files at runtime instead.
- Compression: By default, some file types in
assetsare compressed in the APK. Files with extensions like.jpg,.png,.mp3, and.oggare not compressed (already compressed formats). UseaaptOptions { noCompress }inbuild.gradleto control this behavior. - WebView URL path: When loading assets in a WebView, use
file:///android_asset/(withandroid_asset, singular, notassets). This is a common source of "file not found" errors. - ProGuard/R8: Asset files are not affected by code shrinking, but make sure your asset paths are not hardcoded in strings that might be optimized away.
Summary
- Place the
assetsfolder atapp/src/main/assets/ - Create it via New > Folder > Assets Folder in Android Studio or manually
- Access files with
getAssets().open("filename") - Use
assetsfor files needing subdirectories or arbitrary naming; useres/rawfor simple files that benefit from resource IDs - For WebView, use the
file:///android_asset/URL scheme
Related reading
- Where to remove observer for NSNotification in Swift?
- Where to store global constants in an iOS application?
- Where's the difference between setObjectforKey and setValueforKey in NSMutableDictionary?
- Which Android IPC model to choose
- Which Android Priority Job Queue Asynk Task, Multithreading library would you recommend for Android?
- Which Architecture patterns are used on Android?
- Which iOS app version/build numbers MUST be incremented upon App Store release?
- Why am I getting an error Failed to locate or generate matching signing assets in Xcode 6?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.