`No resource found that matches the given name` when referring to an ID defined later in an XML file
Xamarin.Android Version (eg: 6.0):
8.1
Operating System & Version (eg: Mac OSX 10.11):
Windows 10
Support Libraries Version (eg: 23.3.0):
Describe your Issue:
When referencing an ID in an XML file (such as a layout), the error No resource found that matches the given name is generated if the ID is defined later in the file. For example, a ConstraintLayout child which chains with another child. Android can deal with the later definition, so Xamarin should be able to as well.
Steps to Reproduce (with link to sample solution if possible):
Example layout xml:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/two"/>
<Button
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/one"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
The line app:layout_constraintEnd_toStartOf="@id/two" will generate the error, as @id/two is not defined yet.
Include any relevant Exception Stack traces, build logs, adb logs:
Is there a way to get around this? I have this problem as well.
@FarizF Make the first usage of the id @+id/x, regardless of if it's the actual object being referred to as the ID. That should work temporarily.
Seems to have a work around
I'm having the same issue, but the above solution won't work in my scenario.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/keyboard_1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/keyboard_2"
app:layout_constraintBottom_toTopOf="@id/keyboard_4"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintVertical_chainStyle="packed"
android:text="1" />
<Button
android:id="@+id/keyboard_2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/keyboard_1"
app:layout_constraintEnd_toStartOf="@id/keyboard_3"
app:layout_constraintBottom_toTopOf="@id/keyboard_5"
app:layout_constraintVertical_chainStyle="packed"
android:text="2" />
<Button
android:id="@+id/keyboard_3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintStart_toEndOf="@id/keyboard_2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/keyboard_6"
app:layout_constraintVertical_chainStyle="packed"
android:text="3" />
<Button
android:id="@+id/keyboard_4"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toBottomOf="@id/keyboard_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/keyboard_5"
app:layout_constraintBottom_toTopOf="@id/keyboard_7"
app:layout_constraintHorizontal_chainStyle="packed"
android:text="4" />
<Button
android:id="@+id/keyboard_5"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toBottomOf="@id/keyboard_2"
app:layout_constraintStart_toEndOf="@id/keyboard_4"
app:layout_constraintEnd_toStartOf="@id/keyboard_6"
app:layout_constraintBottom_toTopOf="@id/keyboard_8"
android:text="5" />
<Button
android:id="@+id/keyboard_6"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintStart_toEndOf="@id/keyboard_5"
app:layout_constraintTop_toBottomOf="@id/keyboard_3"
app:layout_constraintBottom_toTopOf="@id/keyboard_9"
app:layout_constraintEnd_toEndOf="parent"
android:text="6" />
<Button
android:id="@+id/keyboard_7"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toBottomOf="@id/keyboard_4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/keyboard_8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
android:text="7" />
<Button
android:id="@+id/keyboard_8"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintTop_toBottomOf="@id/keyboard_5"
app:layout_constraintStart_toEndOf="@id/keyboard_7"
app:layout_constraintEnd_toStartOf="@id/keyboard_9"
app:layout_constraintBottom_toBottomOf="parent"
android:text="8" />
<Button
android:id="@+id/keyboard_9"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_min="48dp"
app:layout_constraintHeight_min="48dp"
app:layout_constraintWidth_max="150dp"
app:layout_constraintHeight_max="150dp"
app:layout_constraintStart_toEndOf="@id/keyboard_8"
app:layout_constraintTop_toBottomOf="@id/keyboard_6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="9" />
</android.support.constraint.ConstraintLayout>
@zlannin What isn't working? You don't appear to have applied the workaround I suggested in that XML.
@cyberjacob I misinterpreted your solution! Once I added @+id/{id} as you suggested to my constraint attributes everything worked 👍
I have the same problem, but I can't move {@+id} before usage, because I use third-party aar with layouts. Is there any another case for fix this problem?
@cyberjacob I've been trying multiple different suggestions for fixes to work around this issue, for the past 3 hours. You're a saint!
Same issue with me your solution cannot solve my problem ` <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:id="@+id/parentlayout" android:layout_width="match_parent" android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>`
@gopalawasthi123 What element is it complaining about?
@cyberjacob it gave me a compile time error that no resource found
the exact error is: No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'ellipsizetest.ellipsizetest'
@gopalawasthi123 can you post the xml file you are talking about, your example above doesn't show the attribute layout_constraintLeft_toLeftOf.
<?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:id="@+id/parentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/facebook"
android:layout_constraintLeft_toLeftOf="parent"
android:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="wrap_content"
android_layout_height="wrap_content"
android:text="Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a"
android:layout_constraintLeft_toRightOf="@+id/imageView"
android:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
Here is the Code
@gopalawasthi123 Did you add the Xamarin.Android.Support.ConstraintLayout nuget package to your project? Also you have android:layout_constraintLeft_toLeftOf="parent" and it should be app:layout_constraintLeft_toLeftOf="parent"