+-
AAPT: 错误:未找到资源 drawableexample (aka com.app:drawableexample)

我在可绘制文件夹中添加了一个形状,如下所示。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:color="#7A828D" android:width="1dp"/>
    <solid android:color="@color/white" />
    <corners android:radius="8dp"/>
</shape>

然后我把这个加入到我的布局中。

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:background="@drawable/shape_info_bg_1"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/sl_userid"
            android:layout_marginBottom="20dp">
            <ImageView
                android:id="@+id/img_info"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:src="@drawable/ico_info"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_marginStart="20dp"
                />
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                tools:text="asdasdasdasda"
                android:fontFamily="@font/medium"
                android:layout_marginEnd="50dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/img_info"
                app:layout_constraintTop_toTopOf="@id/img_info"
                app:layout_constraintBottom_toBottomOf="@+id/img_info"
                android:layout_marginStart="15dp"/>
        </androidx.constraintlayout.widget.ConstraintLayout>

当我在真实的设备上构建时,我得到以下错误。

...\src\main\res\layout\activity_login.xml:41: AAPT: error: resource drawable/shape_info_bg_1 (aka com.xxxxx:drawable/shape_info_bg_1) not found.

    AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"C:\\Users\\xxxx\\Documents\\xxxx\\app\\src\\main\\res\\layout\\activity_login.xml","position":{"startLine":40}}],"original":"C:\\Users\\xxxx\\Documents\\xxxx\\app\\src\\main\\res\\layout\\activity_login.xml:41: AAPT: error: resource drawable/shape_info_bg_1 (aka com.xxxx:drawable/shape_info_bg_1) not found.\n    ","tool":"AAPT"}

> Task :app:mergeExtDexDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\xxxxx\Documents\xxxxx\app\src\main\res\layout\activity_login.xml:41: AAPT: error: resource drawable/shape_info_bg_1 (aka com.xxxxx/shape_info_bg_1) not found.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BU�LD FAILED in 12s

我总是以这种方式添加形状,没有问题。我无法解决这个问题。我从来没有遇到过,你能帮助我吗?

0
投票

只需点击清理项目,然后进行重建。

它肯定会解决你的问题。如果不能解决,只需删除你添加的文件,重建项目,再添加文件,然后再建立项目。

0
投票

删除该文件并建立项目。

再次创建您已删除的文件。