【问题标题】:AAPT: error: resource drawable/example (aka com.app:drawable/example) not foundAAPT:错误:找不到资源可绘制/示例(又名 com.app:drawable/example)
【发布时间】:2020-04-08 17:36:39
【问题描述】:

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

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

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

【问题讨论】:

  • 请再次检查shape XML文件的名称?
  • @Dharmaraj 我仔细检查了文件名。

标签: android layout drawable


【解决方案1】:

点击清理项目 然后重建

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

【讨论】:

  • 我当然试过了。但它没有发生。问题源于在 Windows 中使用土耳其语键盘。
【解决方案2】:
  1. 删除文件并构建项目。

  2. 再次创建已删除的文件。

【讨论】:

    【解决方案3】:

    我在继承的项目中遇到此错误,该项目刚刚从 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'
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2019-01-29
      • 2019-12-26
      • 2019-05-01
      • 2021-07-24
      相关资源
      最近更新 更多