AAPT:错误:找不到资源drawable/example(又名com.app:drawable/enxample)



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

<?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>

当我在真实设备上构建时,我会出现以下错误;

...srcmainreslayoutactivity_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:UsersxxxxxDocumentsxxxxxappsrcmainreslayoutactivity_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

我总是用这种方式添加形状,没有问题。我解决不了这个问题。我以前从未见过面,你能帮我吗?

只需清理项目然后重建

它肯定会解决你的问题。如果不会,只需删除您添加的文件,重建项目,再次添加文件并构建项目

  1. 删除文件并构建项目。

  2. 重新创建已删除的文件。

我在继承的一个项目中遇到了这个错误,该项目刚刚从NativeScript 4更新到NativeScript 6。

我的解决方案是将资源文件夹移动到正确的位置,这样构建就会拾取它们并将它们添加到输出构建文件夹中:

'app/App_Resources/Android/' to 'app/App_Resources/Android/src/main/'
'app/App_Resources/Android/drawable...' to 'app/App_Resources/Android/src/main/res/drawable...'
'app/App_Resources/Android/values' to 'app/App_Resources/Android/src/main/res/values'

裂变

相关内容

最新更新