Assets in Android Studio can not be found - android

I have imported an existing Android Project from Eclipse into Android Studio. I had my assets like icons in the src/main/res folder. When I tried to run the app the following error occured:
Content is not allowed in prolog: my_logo.png
So I searched for a solution and found out that I should use "src/main/assets" instead of "src/main/res". I then created the assets folder by clicking on "File -> New -> Folder -> Assets Folder", moved the content of the res folder to the new assets folder and tried to run the app again. Now I am getting this error:
No resource found that matches the given name (at 'icon' with value '#drawable/my_logo').
It seems like Android Studio does not look inside the new assets folder for the resources. How can I fix this? Thanks a lot!

You shouldn't need the assets folder for image resources. Images should be placed inside a drawable folder in your project's res directory.
The reason it's not finding the image now is because #drawable looks for an image resource in the res/drawable/ folder.

Related

Android Studio: Drawable Folder adding subdirectory or create new folders issue

I am trying to do one of two things
add subdirectory to the drawable folder, as I have away team and home team that need to be in separate folders.
It seems that it can not be done.
So I am trying the following where I create 'top' folders like aTeam and hTeam by adding New Resource Directory and give them the name of aTeam and hTeam with the resource type of drawable.
The folders are created in the project folder structure but they are not being displayed in the android studio project and I can not reference them?
does anyone know what i am doing wrong?

"Incorrect Directory" while adding resource file in android studio

I am trying to add resource file in android studio by right clicking on res folder but it is showing an error "Incorrect Directory". I don't know what I am doing wrong. Any help is appreciated.
Same problem occured with me.
This problem occurs because of same directory already present in the 'res' folder.
All you have to do is to navigate to 'res' folder in file explorer and you will see a folder created by you earlier OR a folder other than these folders:- 'drawable' ,'minmap' ,'layout' ,'values'. Delete other folders keeping these four folders untouched and try to create resource layout file again !!!!
Same problem occurred with me. This problem occurs because of same directory already present in the res folder. All you have to do is to navigate to res folder in file explorer and you will see a folder created by you earlier OR a folder other than these folders:- drawable, minmap, layout, values. Delete other folders keeping these four folders untouched and try to create resource layout file again.

Images and Directories not showing in Drawables directory

I imported a number of image assets, and I copied the assets into the project by copy/paste them into the project via Finder on my Mac. I've done a clean/rebuild on the project, and the files & directories showed for a moment, but then they disappeared. Now I can't get the files and the directories to show up. The files are clearly in the directory and project, but they don't show in Android Studio. They are labeled drawable-hdpi, drawable-mdpi, and so on. Here is an image of the files:
Here is my Android Studio:
Switch in project view will show you all folders for example drawable.hdpi and so on check all these folder for all images.
It turns out that I added my images to the drawables directory rather than the resources directory! Ugh...

Android Studio newly created folders not showing

I am using Android Studio 2.1.1 (currently the most updated stable version).
I created new directory inside 'res' by name "values-21"
and it don't shows up.
But if I go to the physical location of 'res' on the hard drive I can see that its exist.
and of course I checked using both Android and Project Files structure but either way its not showing it.
I wanted to check where is the problem so I created another directory by name "menu", and the last one was shown.
just to be sure I tried to create the same directory again ("values-21") but Android studio didn't allowed it because this directory allready exist's.
any ideas how to fix it?
Update - the solution is to create new directory using the "Android resource Directory" option and not by "Directory" option.
all you values xml files stored in values, values-21, values-mdpi or other physical folder in AndroidStudio displayed in one res/values folder.
It will not show until you copy a XML file into values-21, android studio consider all values folders to be of same family and it shows only one folder and the files with post script of the family in which it lies.
copy some layout file from resource directory and through windows explorer paste in that the folder that you have created i.e values-21 and now come back to android studio and check the folder should be there.
Happy coding

Assets folder in android app (eclipse)

I had searched to create the assets folder in an android app, the solution which i had tried is <App Name>/src/assets/fonts/
but when i try to use a ttf file in my Application, i have an error :
the code :
mFace = Typeface.createFromAsset(mContext.getAssets(),"fonts/fontType.ttf");
and the error :
native typeface cannot be made
I don't know if the assets folder is in the good place.
The problem is at the path of asset
<App Name>/src/assets/fonts/
should be
<App Name>/assets/fonts/
Read more at Directory Structure of an Android Project
Android project directory structure is as below
In Android Studio, I tried the root "app" folder, and that didn't work. I looked for the AndroidManifest.xml file and put the assets folder there. That worked for me.
For me it ended up being app\src\main\assets
ProjectName/assets/fonts
Not in under the src.
The assets folder is an independent folder.
While creating an Android project itself the Assets folder is independent to the src folder. Not inside the src folder.
Confirm that assets folder was created in the following way /assets.
Later create a fonts folder inside the assets folder and place fonts file inside the fonts : /assets/fonts

Categories

Resources