Where to place the 'assets' folder in Android Studio?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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

