android build splash.9.png error - android

I have a build fail due to the following error
[aapt] res/drawable-xhdpi/splash.png:0: error: Resource entry splash is already defined.
[aapt] res/drawable-xhdpi/splash.9.png:0: Originally defined here.
Any ideas? Thanks!

This error could also happen, if you use cordova and renamed an existing image (in my case there was only splash.9.png present, but the same error occurred.
In this case you need to clean the project, using
./platforms/android/cordova/clean

You cannot include something.png and something.9.png at the same time. Delete or rename one of them.

All of the above answers where wrong for me :D
The problem was, that ive had already compiled once with files named splash.png (actually: screen.png in my case).
After draw9patching and renaming them to .9.png (which you have to in order to make them work) I had to remove all files in ant-build to get rid of the error: the compiler seems to sort of correctly fail because he gets two different files with the same name by ignoring the different extension.

You have two files in resources splash.png and splash.9.png.You cannot include splash.png and splash.9.png at the same time.
Delete the file not being used and the compile you will be able to build successfully.

As you are using two image with same name, one is simple one and another is nine patch which cause error, delete one of which you are not using or you don't wanna use.
which is not in use then delete splash.png or /splash.9.png

rename the splash.png to something else. splash.9.png is valid if it is 9-patched. But you cannot keep both splash.png and splash.9.png.

Rename splash.9.png to splashnew.png .
Never use "." "_" etc other special characters for your resource images and files!
You can remove the dots and name it splash9.png
Ref:http://developer.android.com/tools/help/draw9patch.html
Note: A normal PNG file (.png) will be loaded with an empty one-pixel border added around the image, in which you can draw the stretchable patches and content area. A previously saved 9-patch file (.9.png) will be loaded as-is, with no drawing area added, because it already exists.

To me this was my solution
First perform this action
cordova clean
And you can now do this
cordova build android

Related

Could not select images from drawable folder

I am trying to add an image slide on my android app.
When I try to add the source for the image, from drawable folder, I can't select the iamges.
Here, a little screenshot to understand better the problem:
Screen
What can I do to solve it?
Thank you for your answer.
the naming convention shouldn't be a number. declare it in small letters, like this -> image_one ......e.tc.
You should use PNG or WEBP images as your drawables.
As you may already know variable names should not start with a number. So in your case using a number as your image name forces the compiler to generate a variable named as your drawable name which cannot be accepted in programming, hence the constant R.drawable.1 does not get generated. Try renaming your drawable to an alphabetical equivalent.

Android drawables are not recognized by AndroidStudio if I use dpi subfolders

I have just started the Treehouse Android development course, I have also asked this question on their forums without any luck.
DATA
AndroidStudio v 1.2.2, the course is based on v0.86 I think
OS / DE: Manjaro Linux, KDE
I have copied the image files inside the drawable folder, each into their specific dpi folder.
I have created the ImageView for a mail_title.png, and added the src as the full path to the png. When I do that, the image loads into the preview screen, and I can work with it, but If I try to build the app it just says the value of src cannot be a string.
So then I tried to point to it as a resource. On many forums and the android documentation I only found that I should reference it through a "pointer" #drawable/main_title , when I downloaded the projectfiles from the course I saw thats how they did it too.
If I try to rebuild now it gives the following error:
Error:(14, 22) No resource found that matches the given name (at 'src' with value '#drawable/main_title').
Then I tried to create a resource inside strings.xml, I found some autocomplete function that pointed me in "the right direction", of course it did not work!, same error as before. I have tried using absolute paths as well without luck.
Right now It shows R as "cannot resolve symbol R" in the MAinActivity file. I figured out by reading online that this is due to my drawable not existing problem.
Then I created a refs.xml in values and added
main_title.png
I actually tried with and without the extension (png)
After that I clicked on the IDE suggestion to create a drawable folder and it just created a #drawable folder inside of layout....
Basically it says it cannot resolve directory #drawable from activity_main.xml
and also
Error:(3, 33) String types not allowed (at 'main_title' with value 'main_title.png'). on the refs.xml file (this happens whether I use the extension (png) or not.
The only solution I have found is to just copy one version fo the images to the main drawables folder, and deleting all of the subfolders, if I don't delte them then it also doesn't work...
So, as you can see I'm kinda lost... Any help would be appreciated. I'm a python backend developer and I'm pretty comfortable usiong Pycharm (IntelliJ for python), but somehow I feel Android Studio has me totally lost!
So, in case anyone wonders, I solved it following both Cris and Rob advices. I installed appcompat v7 and put my img resources (png,jpd, etc) directly inside my drawable folder. Then I created a folder for each dpi resolution inside the res folder, NOT inside the drawable folder.
I use eclipse but i think its pretty much the same, you should have you various drawable folders, then you have to include the R (res folder)
import com.example.project.R;
and then call them by reference
R.drawables.main_title
Note you dont need to specify which drawable folder , adroid does that for you.
Also if you are getting unresolved errors with R then you may need to have the appcompatv7 library inlcuded in your project.

How to use ImageView in the Design Editor of AndroidStudio?

I'm working through the Sunshine App tutorials and am really stuck on putting an ImageView in my UI. Everything I've found has been doing it in the XML file and even those that I tried copying and pasting didn't work.
At first I had the ic_launcher only in the App Folder. Then after reading other solutions XML file I right clicked on main/res/drawable and did New→Image Asset so now all of those mipmap- contain the ic_launcher.png and it's still in my app as well, as you can see:
But now I've got no idea what to do for it to actually work. I tried a few things in the SRC, which seems to be where it goes:
#mipmap-hdpi/ic_launcher
#drawable/ic_launcher
ic_launcher
#mipmap/ic_launcher
None have worked.
I see that you are getting
Failed to convert #drawable/... into a drawable
I'm not sure if this will work, but you could try restarting your Android studio.
Android: failed to convert #drawable/picture into a drawable

Image in android not getting added to #drawable/

Hello I am developing an android application in which for a ListView I have to added an image to drawable folder but when I am adding it is giving the error.
This is the folders hierarchy of my project
This is the image I wanna add arrow.png
This is the error
[2013-04-03 20:57:37 - FileSharing] res/drawable/arrow.png: Invalid file name: must contain only [a-z0-9_.]
I have changes the file name 10 times according to the conventions but still the error is not going
Well i think you must not put the image file in drawable folder.
you must chose these folder for putting images for your application
If you didn't see these folder create these folder inside res .
Then clean and rebuild your project .Hope this would help you
Also Keep an eye one the name of images must contain only [a-z0-9_.]
I think the default choice is drawable-mdpi folder
Refer this
Clean your project and build again.
Sometimes eclipse behaves wierd.

Resources NotFoundException?

I'm getting crash reports from android marketplace:
android.content.res.Resources$NotFoundException: Resource ID #0x....
I get about 17 of these a week. It's pointing me to the following in my code:
context.getResources().getDrawable(R.drawable.foo);
That resource is definitely present in my /drawable folder. I have several hundred thousand installs, I'm not sure how this could be failing for some users, but working for the vast majority. I'd like to find out what's going on, because they can't use the app in this state. Any ideas?
Thanks
--------- Update ----------------------
Also I can see the entry for the drawable in question in my R.java file, looks like:
public static final int foo=0x7f020034;
I do a clean build of the project, then straight after that do my release build (no code modification in between to give the automatic eclipse build stuff possibly let the R file go awry)
Thanks
I got this exception:
Resources$NotFoundException: String resource ID
when I was using setText with an int value. I had to convert it to String.
Before:
myTextView.setText(obj.SomeIntProperty);
After:
myTextView.setText(String.valueOf(obj.SomeIntProperty));
Is the crash reports coming from version <=1.6, and you have certain resources only in qualified folders, i.e. "drawable-mdpi" instead of just "drawable"? If so then read about "Known issues" at the bottom of this page.
The same problem I found on my application today morning and found a very simple solution to this. the problem looks big and complicated but it's not.
Steps which I followed are
Delete the bin folder it self
Clean the project
Remove application from your device
Run the application and check your scenario.
According to me it should not give this exception again.
Reason : When you build the application R.java contains all the memory address and it happens that those address are invalid for next run.
Second Reason : When you have the application which supports lanscape and portrati mode both and if you have not wrote the XML file for either of them then it's the possibility that may lead to this kind of crash. and there are pretty much chances of OutoFmemory and Memory leak issues when you have to support both the modes. please think on this as well.
This have occurred several times especially on phones with low density. I also noticed that it mostly happens with 9-patch images.
My solution was to include 9-patch images in as much density resource folders as I could (mdpi, ldpi, hdpi, xdpi).
You have included certain codes that reference content from Android SDK.
For example, I faced a similar issue once and when I removed the line
android:background="?android:attr/actionBarItemBackground"
from my xml, everything works fine again.
Heh, no idea, I'm actually working on a similar issue, but it could be it. It's worthwhile mentioning that while the device can upscale resources and layouts, it cannot downscale them. So if you have minimum values, set them in the AndroidManifest.xml. Try adding layout-ldpi and layout-small first.
A useful technique for logging which layout got loaded is to attach an android:tag to every root container of your layout XML file, and in onCreate() after setting setContentView(R.id.layout) just print the value of the tag. It will tell you which got loaded - you still have to plug the hole by adding all possible combinations, if just for debug purposes.
also, rename your drawables to drawables-nodpi folder to ensure no drawables are missing. this turns off internal scaling, makes APKs smaller and doesn't "pick" from any other drawable folder.
once you figure out whether it's the layout or drawable, additional metrics will help you find the root cause. for now, check the layouts first with "always use" drawables.
on monday when i get back to the office I'll post you the metrics code used to measure data captured in this thread - Which part of Android is in charge of picking a correct resource profile?
In my case I had a layout file that lead to the crash:
I got the following log-
That showed this link to my actual code:
Which is this line of code:
I checked my file navigator folder names as suggested by the most popular answer and it looked like the resource that is supposedly missing is in the normal layout folder
but when looking under the Project file navigator rather than the Android file navigator I was able to see that not only was the supposedly missing resource file not in the normal layout folder, but I didn't even have a layout folder without a special extension.
Adding an Android Resource Directory to the res folder and calling it layout and then pasting over the resources from your speciality folder (ex. layout-sw720dp) into it fixed the issue for me.
This solution will also work for other folders as suggested such as not having files in drawable and only having them in drawable-xxhdpi can be fixed by moving the file into drawable and tweaking it as needed. Good luck folder fiends!
This could also happen if the resource you are referring to (lets call it ResA) is in-turn referring to a resource which is missing (lets call it ResB).
Android will raise the ResourceNotFoundException for ResA even though whats really missing is ResB. Such is life!
In my case, ResB was defined in the values-swxxxdp but not in values. Hence I was getting this exception on phones but not on tablets.
The error can happen when portrait XML layout file is not defined. It doesn't happen all the time, but happens for example if user quickly turns off and on the phone, I suppose in that case the system calls the onCreate in portrait orientation, before calling onCreate in landscape.

Categories

Resources