Assets Folder Not Getting Added To Android Studio Project and APK
Asked Answered
C

4

8

I'm trying to add an Assets folder to my Android Project in Android Studio 2.1.2. I right click on the project and choose New -> Folder -> Assets Folder. In the project pane on the left, it doesn't show up when Android is selected. If I switch to Project Files, it does appear, however it looks like a normal directory, rather than looking like a resource directory. I then tried adding files to it (jpgs), both through Android Studio and through the file explorer (all file names are lowercase with no special characters). If you unzip the apk that gets created though, it doesn't contain an Assets directory or the added files. Also sometimes the assets directory will disappear from the project files pane, although it's still in explorer.

What step am I missing to get to the Assets directory properly added to my project?

Note: this is for a LibGdx project that expects image files to be there.

Custombuilt answered 26/7, 2016 at 13:17 Comment(2)
I thought LIBGdx creates that folder by default or did you delete the initial folder? Try generating a new project to see if the default asset folder would be readily available. If it is, then it's an issue with your prior project structure and not the IDEZeitgeist
I added Libgdx to my existing android app. Works well aside from this. But I don't think it's libgdx's fault since as far as I can tell the assets folder and files aren't getting added to the apk, which is independent of libgdx.Custombuilt
C
15

Finally got it. Appears to be a bug in Android Studio, but to make it work, in the Project pane, go to Android view and (this next part is critical) right click on the res folder and go to New->Folder->Assets folder. You might want to click change folder location to be sure it's going into the main folder (mine was) just to be on the safe side.

You must right click on the res folder. That was my issue. If you right click on the module or anywhere else, even though the folder will get created in the proper spot, Android Studio and gradle won't treat it as a resource directory and just ignores it.

Custombuilt answered 26/7, 2016 at 14:48 Comment(0)
R
7

Be sure to create folder in app/src/main/ and call it assets.

Reclamation answered 26/7, 2016 at 13:52 Comment(5)
that's where it is. not getting added to apk though and not showing up in most panes of android studioCustombuilt
This is my full procedure: From Project View go to app/src/main and select: new -> Directory. If I name it assets, folder icon indicate it is a resource folder and it's visible from Android View. If i make typo, like naming it asset or any other parent folder, it won't work.Reclamation
Darn, that's just not happening for me. I'm certain that's my problem though. Question, when you're in the project pane, what is the sub pane? Is it Android, Project Files, Packages, Default, etc? It's displayed on the top of it. Thanks!Custombuilt
In Project pane I select Project to add the directory. I also tested it manually, it works fine. Open file explorer, locate your project, and add new folder assets inside main folder (project_name/app/src/main). I don't use LIBGdx, maybe that's the problem, even though it shouldn't be any different for any project.Reclamation
Finally got it. I'll post the answer below. Think it's a bug in newer versions of Android Studio. They must be changing this functionality and it's a work in progress. Thank you for all the help thoughCustombuilt
C
2

For me in Android Studio 3.6.2, the assets folder wasn't showing up in the "Android" view, no matter where I tried to create it, after trying the other suggestions here. In the "Project" view it showed up in app/assets as a plain folder. I then drag-and-dropped it to src/main/assets and it automatically changed its icon to the same icon as the res folder, and after this it is now also showing up in the "Android" view, so I guess Android Studio is picking it up correctly now, and it appears to be a bug in Android Studio.

Cedeno answered 5/4, 2020 at 17:19 Comment(0)
I
1

If you created a folder in your res directory and named it "assets" and now as "Nullqwerty" mentioned you could not able to solve your problem and you face to the duplication error, just go to the project tab (or press Alt + 1) and in the view mode, change it from "Android" to "Project", then expand all folders in your project to find assets folder in your src\main\res directory (or in src\main path) and right-click on your "assets" folder (if you created it before by adding a "Directory" and named it assets), then change your view mode from "Project" to "Android", again, and right-click on "res" directory->New->Folder->Assets Folder. Then click on "Finish" button to see the assets folder on your main directory as you want. That's it ;)

Imminent answered 2/9, 2022 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.