Execution failed for task 'app:process:DebugResources' - android

So out of the blue I've ran into this problem. This is the Gradle Build console output:
https://i.stack.imgur.com/YxvfR.png
I've checked some posts online (mostly SO). So far I've changed the buildToolsVersion (which it doesn't let me be lower than 25.0.0), did Clean Builds, Restarts, checked all XML files for problems.
Nothing solved it. Also I didn't find anything about the first few errors ("No resourse matches..."). I tried to change those files to delete those lines but 1)"They're not part of the project" 2)If I change in anyway there's another error.
I've also returned to previous builds of my code, which worked and somehow now they all show the same errors.
Can you point me in the right direction? I want to understand what's wrong and how can I solve this?
[UPDATE]
Here's the code for res\layout\abc_list_menu_item_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="?attr/listPreferredItemPaddingLeft"
android:layout_marginRight="?attr/listPreferredItemPaddingRight"
android:duplicateParentState="true">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
android:duplicateParentState="true" />
</RelativeLayout>
<!-- Checkbox, and/or radio button will be inserted here. -->
And this one's for res\layout\abc_popup_menu_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:minWidth="196dip"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.InternalGroup">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="?attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:textAppearance="?attr/textAppearanceSmallPopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
</RelativeLayout>
<ImageView
android:id="#+id/submenuarrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:scaleType="center"
android:visibility="gone" />
<!-- Checkbox, and/or radio button will be inserted here. -->
The difference of these two to the res\merged\debug\SAME_NAME is none other than an error on the line xmlns:android="http://schemas.android.com/apk/res/android"saying URI is not registered. Since both of these files were created automatically I have no idea what's going on. I've searched this last "URI not registered" error but all the solutions presented are so different and seem so specific to one's project that they don't seem to apply here. I tried using Build Variant "release" and then changing it back but nothing happened again.

This happens out of the blue for me as well. I'm paying attention as to why that happened, but the solution is to clear the build cache.
To execute the task, select View > Tool Windows > Terminal from the menu bar and use one of the following commands:
For Windows: gradlew cleanBuildCache
For Mac or Linux: ./gradlew cleanBuildCache
For future reference and related options, check out this link:
Clear the build cache

Now, I finally got this to work but have simply no idea why or how it started working. So I had this ListView in one of my layouts and I wanted to add another in other layout. For some reason, when I created the second it changed the IDs of the first (one of them was 'title').
I deleted both ListViews but the problem persisted. So when I realized that I had the ListView with a 'title' id I decided to do it again with the first IDs and now everything works.
Couple of questions:
Why did the second ListView changed the first's IDs? - I created a Layout for the ListViews and seperate adapters since I wanted to show them in different ways.
Why deleting the layouts and the adapters did not solve the issue at first?
Plus, I still have an issue which is related. When I press the 3dots on the Toolbar (overflow), the app crashes. It throws a NullPointerException at ListMenuItemView. When I go to one of the faulty files in the question it says that it Cannot find the declaration of android.support.v7.view.menu.ListMenuItemView... Any ideas on what's going on?

Related

Android: Creating custom support v7 preference not working as Expected

I have created a sample demo application for the custom Android preference using support library preference-v7.
Code: https://github.com/saurabhkpatel/Android-Custom-Preference-Sample
I am facing two problems here:
In this demo application, I have total three different types of preferences. One is ListPreference, Second is Custom Preference which I have created and the last one is SwitchPreferenceCompat. If I put Custom Preference in between these two preferences categories then it's not working expected. Please check this attached screenshot. You can see that third SwitchPreferenceCompat is missing.
Even I can see the seek bar twice which comes from custom layout file, but I have only one seek-bar over there.
Everything is working fine if I put SampleCustomPreference at last.
Any ideas, Why this behavior is happening?
Thanks for your time.
UnExpected
Expected
The layout file layout_pref.xml has an issue. The height of the parent layout should be wrap content not match parent. Corrected xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#android:id/title"
style="#android:style/TextAppearance.DeviceDefault.SearchResult.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C Title" />
<TextView
android:id="#android:id/summary"
style="#android:style/TextAppearance.DeviceDefault.SearchResult.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C Summary" />
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Items Don't Stay Where Placed With Drag Drop Feature in Android Studio

So Android Studio has the drag/drop feature in the design tab. I am able to place the elements where I want them, and the layout looks great on the screen.
However, when I go to run the app emulator, it looks completely different. Everything gets shoved up to the top-left hand corner of the screen, nowhere near where I placed it in design mode.
Is there a way to have your elements show the same way in the emulator, as the way you place them in design mode? Right now I'm having to go back and edit all the code each time.
I have my code below, as well as a image link below to further clarify my point.Comparison of Design mode vs App Emulator
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.luke.currencyconverter.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter The Amount in Dollars"
tools:layout_editor_absoluteX="-159dp"
tools:layout_editor_absoluteY="126dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="403dp"
android:layout_height="0dp"
android:text="Enter The Amount in Dollars:"
android:textColor="#android:color/black"
android:textSize="22sp"
tools:layout_editor_absoluteX="33dp"
tools:layout_editor_absoluteY="365dp" />
<ImageView
android:id="#+id/currency"
android:layout_width="361dp"
android:layout_height="450dp"
app:srcCompat="#drawable/currency"
tools:layout_editor_absoluteX="12dp"
tools:layout_editor_absoluteY="-117dp" />
<Button
android:id="#+id/convert"
android:layout_width="361dp"
android:layout_height="wrap_content"
android:onClick="convert"
android:text="Convert"
tools:layout_editor_absoluteX="12dp"
tools:layout_editor_absoluteY="462dp" />
<EditText
android:id="#+id/dollarField"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="408dp" />
</android.support.constraint.ConstraintLayout>
Drag and drop for android will only place the object within the screen. To keep it there you should modify the xml so that the objects will be constrained to each other.
You can use either relative layout or constraint layout for an easier time in designing your layout.
I figured it out. I was using "constraint layout", and I needed to use "relative layout".
I just had this error as well and as annoying as it sounds, my solution was to delete my xml file and recreate it.

RelativeLayout not working properly Android

I have the next problem: I use a lot the RelativeLayout, like the Android documentation is telling me to do. But, since few days, I don´t understand why, this is not working anymore:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
This is my layout, very simple. So, according to this one, the textView should be BELOW the button, but, instead, it appears OVER the button!
.
Сan anyone explain me what happens?
EDIT: The problem is not when I try to run it on a device, the problem comes when I see it on the graphical layout of the ADT Plugin for Eclipse...
I try this code it's working properly.
If your side not working properly Try to Clean build your project and then Run.
If still having problem then Try this
android:layout_below="#+id/boton"
remove above line with this
android:layout_below="#id/boton"
Because "+" create new reference to R.java file
This may be the issue.
try by removing the below line from your code
android:layout_marginTop="60dp"
Take the '+' sign out of the TextView's layout_below attribute. The '+' tells it to deine a new id. Without the '+' it should refer to the existing one.
I think your issue is the drawable for the background, since I am not seeing an image in your preview.
Having this issue is giving you a build error so the preview doesn't show the layout in its current state (it reverts to the last sucessful build). Either remove that line and save to see the preview or check to make sure that you have an image in your drawables folder titled "background"
Try this, without the drawable to check if it is working for you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
I am trying to run it, and now, I know what´s the problem.
When running the app in a terminal, it is working properly, the problems comes when I try to see it on the graphical layout on the ADT plugin on Eclipse! Anyone with the same problem??
Add </RelativeLayout> at the end of your relative layout to close it.

Android xml error: "No resource found that matches the given name" with RelativeLayout (#id/LinearLayout_acc, #id/ProgressBar_statusScreen)

Okay, so this is starting to really annoy me. This error pops up in a very special, not very logical way.
Let me start out by saying that I have already looked at the other questions regarding this error, Google'd it too. As far as I can tell, most similar problems occur because people refer to a String resource or something else not within the same layout file, they misplace the '+' in '#id+' or something similar.
The problem I am having occurs in a layout .xml file with a RelativeLayout. This contains a TableLayout, two LinearLayouts containing some text and finally a ProgressBar. What I want is the progress bar to be aligned with the relative layout using android:layout_alignParentBottom="true" and then align the two linear layouts above the progress bar (the bottom linear layout aligning above the progress bar, the other aligning above the bottom linear layout).
It should be simple enough and looks as if it works, i.e. the graphic view shows the desired result. However, and here comes the problem, Eclipse gives me an error on the two linear layouts,
"Error: No resource found that matches the given name (at 'layout_above' with value '#id/LinearLayout_acc')."
and the same error for the other linear layout referring to the progress bar. I have more than triple checked that there are no typos (the id's also exist in packagename.R.java), and I have tried cleaning the project a dozen times.
I don't get the error when saving (and auto building), not until I decide to run the project. Another weird thing is that when I refer to the bottom linear layout from the progress bar instead of the top linear layout, I get no error!
My layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_activity" >
<TableLayout
... />
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_above="#id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
... />
<TextView
... />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout_acc"
android:layout_above="#id/ProgressBar_statusScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<TextView
... />
<TextView
... />
</LinearLayout>
<ProgressBar
android:id="#+id/ProgressBar_statusScreen"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp" />
</RelativeLayout>
Please help, I have no idea what causes this error!
Edit with answers
Shrikant came with the solution of changing the order of appearance in the layout file so that elements reference only other elements already defined when the reference is read.
Also, as others have posted, changing #id/ to #+id/, even in a reference, does remove the error messages. As Marco W. wrote in this thread, the thing is you have to use #+id/ the first time each id is mentioned and then use #id/ afterwards, even though the first time may not be a definition.
I made most of the design and set the referred id's in Eclipse's graphical editor, so code that resulted in an error message was automatically inserted. Maybe this is a bug in Eclipse.
change
#id/LinearLayout_acc
to
#+id/LinearLayout_acc
Please check the below code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/ic_launcher" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/LinearLayout_acc"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FIRST" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SECOND" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/ProgressBar_statusScreen"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THIRD" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FOURTH" />
</LinearLayout>
<ProgressBar
android:id="#+id/ProgressBar_statusScreen"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp" />
</RelativeLayout>
Also check the following link.
It says that android:layout_below="#id/myTextView" won't recognise an element with id "myTextView" if it is written after the element you're using it in.
Change every id #id to #+id, no matter when it's defining or referencing an id. With this, you won't get
Android xml error: “No resource found that matches the given name” with RelativeLayout (#id/LinearLayout_acc, #id/ProgressBar_statusScreen).
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_above="#+id/LinearLayout_acc" <--- here might be a problem you forgot + sign
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >

Why do I keep having problems with R not being resolved?

I have constantly gotten the same error over and over in my program and i can't find out how to fix it. R cannot be resolved to an error. I have tried to build my project and i have no imports that involve .R? Would anyone know how to fix it?
Here's my xml files i can't seem to find anything wrong....
strings.xml
Remote Doc
Remote Doc
Patient Mode
Doctor Mode
About
Exit
Simple Mode
Detailed Mode
About Remote Doc
\
Remote Doc is an application that allows a brace user analyze
how often they use their thing
main.xml
<!-- Patient Option -->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/patientButton"
android:id="#+id/patientButton">
</Button>
<!-- Doctor Option -->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/doctorButton"
android:layout_weight="1"
android:id="#+id/doctorButton">
</Button>
<!-- Exit Mode -->
<Button android:text="#string/exit"
android:layout_weight="1"
android:id="#+id/exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<!-- About Mode -->
<Button android:text="#string/aboutButton"
android:layout_weight="1"
android:id="#+id/aboutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>
/>
main.xml- land
android:text="#string/mainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp"/>
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:text="#string/patientButton"
android:id="#+id/patientButton"/>
<Button
android:text="#string/doctorButton"
android:id="#+id/doctorButton"/>
</TableRow>
<TableRow>
<Button
android:text="#string/aboutButton"
android:id="#+id/aboutButton"/>
<Button
android:text="#string/exit"
android:id="#+id/exit"/>
</TableRow>
</TableLayout>
</LinearLayout>
This is a really common problem. First try cleaning your project by going to Project > Clean.
If that doesn't work, try one of the recommendations from this similar question
R is an automatically generated class in Android. It holds all your ressource references.
Since the creation of that failed, you will most likely have an error inside one of
your ressource files. (e.g. syntax error in a layout file like main.xml, or in your strings.xml). Check these files inside the res/ folder. Probably in the one you most recently edited.
After your are done and found it, this should go away automatically. Sometimes it gets stuck though, then do a project clean. Inside eclipse select Project->Clean.

Categories

Resources