-1

enter image description herei have always added drawable as background to my view before now. but of recent when i add a drawable as background to any view such as LinearLayout, view, TextView i get this error

 error: resource drawable/rectangle_white (aka merchant.com.our.nextlounge:drawable/rectangle_white) not found.
Message{kind=ERROR, text=error: resource drawable/rectangle_white (aka merchant.com.our.nextlounge:drawable/rectangle_white) not found., sources=[C:\Users\USER\Documents\Exolve Project\NextLounge\app\src\main\res\layout\activity_dash_auth.xml:45], original message=, tool name=Optional.of(AAPT)}

I have refreshed, cleaned, build but its not working. the only way it work is if i add multiple drawable API folder such as drawable-v21,drawable-v22,drawable-v23

for it to work. Please how do i fix this issue.

<?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=".activity.DashAuthActivity">
<include layout="@layout/background_auth"/>

  <include layout="@layout/logo"
   android:id="@+id/logo"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   app:layout_constraintLeft_toLeftOf="parent"
   app:layout_constraintRight_toRightOf="parent"
   app:layout_constraintTop_toTopOf="parent"/>
<TextView
    android:id="@+id/text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="@string/intro_text"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/logo"
    app:layout_constraintBottom_toBottomOf="@id/linearLine"
    android:layout_margin="20sp"
    app:layout_constraintVertical_bias="0.0"
    android:padding="8dp"
    android:textAlignment="center"
    android:textColor="@color/white"/>
<LinearLayout
    android:id="@+id/linearLine"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="4"
    android:padding="4dp"
    android:layout_margin="24dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintVertical_bias="0.96"
    app:layout_constraintBottom_toTopOf="@+id/linearButton"
    android:layout_marginBottom="20sp">
    <View
        android:layout_width="0dp"
        android:layout_height="6dp"
        android:background="@drawable/rectangle_white"
        android:layout_weight="2.5"/>
    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="0.3"/>
    <View
    android:layout_width="0dp"
    android:layout_height="6dp"
    android:background="@drawable/rectangle_white_line"
    android:layout_weight="1.2"/>
</LinearLayout>
 <LinearLayout
android:id="@+id/linearButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4"
android:padding="4dp"
android:layout_margin="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

   <Button
    android:id="@+id/buttonSignIn"
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="2"
    android:layout_marginRight="4dp"
    android:layout_marginEnd="4dp"
    android:text="@string/sign_in"
    android:textColor="@color/black"
    android:textAllCaps="false"
    android:textSize="18sp"
    android:background="@color/white"/>
    <Button
    android:id="@+id/buttonSignUp"
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="2"
    android:layout_marginLeft="4dp"
    android:layout_marginStart="4dp"
    android:text="@string/sign_up"
    android:textAllCaps="false"
    android:textSize="18sp"
    android:textColor="@color/white"
    android:background="@color/orange"/>

Below is the rectangle_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
  <stroke android:color="#fff"
     android:width="2dp"/>

</shape>

Error message during Build

Chidinma
  • 19
  • 1
  • 9

2 Answers2

0

At runtime, the drawable that will be picked is the one most suitable with the device's android version,
unless there is only 1 drawable folder, in which case there exists only 1 drawable.
Since the other version drawables in drawable-v21, drawable-v22, drawable-v23 etc work,
but the drawable in the main drawable does not work, this means that the latter drawable is the problem.
I suggest that you inspect it for errors in the xml structure, or if it's possible recreate it.

forpas
  • 160,666
  • 10
  • 38
  • 76
  • I have only one drawable folder and it shows this error during build. but if i create individual API version folder it builds successfully – Chidinma Nov 30 '18 at 11:15
  • *if i create individual API version folder it builds successfully* after you create these folders do you recreate this drawable and put it inside these folders? – forpas Nov 30 '18 at 11:19
  • yes i copy them into into the new drawable folders and it works fine. BUt the downside to it is that i have to create a drawable folder for each API version for it to run on different android phone – Chidinma Nov 30 '18 at 11:25
  • Then the main drawable is the problem. Can you recreate it? – forpas Nov 30 '18 at 11:26
  • i have deleted it and created a new drawable directory and copied all the xml files back and am still having the same issue – Chidinma Nov 30 '18 at 11:27
  • I tested `rectangle_white` that you posted and it works fine. I see in the errors that there is problem with `rectangle_white_line` too. – forpas Nov 30 '18 at 11:36
  • See these similar issues: https://stackoverflow.com/questions/49965610/aapt-error-resource-drawable-not-found, https://stackoverflow.com/questions/48394277/android-studio-errorresource-drawable-abc-ic-ab-back-mtrl-am-alpha-aka-com-i – forpas Nov 30 '18 at 11:43
0

HI thanks guys for all your helpful response. All i had to do was delete the entire drawable folder with all the content, then i created a new drawable folder and created all the file anew. Once i did that i ran it and it worked fine for all android device. so i don't have to create specific folder for different API version

Chidinma
  • 19
  • 1
  • 9