Search code examples
androidandroid-studiointellij-ideaandroid-resources

Android Studio - What is the Java Resources Folder?


I know there are two well-known folders where one can put resources.

The first is the /assets folder, the documentation says:

Contains file that should be compiled into an .apk file as-is. 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.

The second is the /res folder, the documentation says:

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

Now i was wondering, there is a third option to create a resource folder "New > Folder > Java Resources Folder" To me i looks like some part of the Android Plugin in IntelliJ because it has a little Android symbol in front of it .

Any ideas what the use of it could be? I couldn't find any documentation about it.

My first guess would be to use it in situations where you want to supply resources to a JVM Test.


Solution

    • In standard java world

      Resources can be embedded directly in "your source tree" and used with Class's method getResource (see java documentation for a more precise description).

    • In android world

      This practice is not recommanded (do not work at all, because such resources are removed from generated APK). You can still declare Java resources folders (see build.gradle : sourceSets { main { resources.srcDirs = ['src/main/java/yourresourcesfolder'] } } Android studio Java Resources folder And the result in the apk : Generated apk

    • Conclusion

      As resources's folder tree is removed,using java's resource folder become from my point of view, useless (in an android projet). Using android's asset folder is a better choice (also avoid resource's name conflict, but it's an another story :D )