androidxmlaapt

Resource drawable not found but they exist in drawable folder


I'm working on an android application for about 2 months. Almost each time I created custom drawable when I tried to build project I got Android resource linking failed error and after that the name of drawables that couldn't located by android studio.

My solution was that I moved those drawables somewhere out of my project and rebuild the the app after getting error I moved drawables again back to my project and when I rebuild my APK there was no error anymore and I could build, run, even generate APK and those drawables worked perfectly fine. But now that my project finished I want generate signed apk but there is no way that I can get rid of Android resource linking failed error. I put some of my drawables codes below.

retry_btn.xml:

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/register_btn_disabled"/>
    <item android:state_pressed="true" android:drawable="@drawable/register_btn_clicked"/>
    <item android:state_pressed="false" android:drawable="@drawable/register_btn_normal"/>
    <item android:drawable="@drawable/register_btn_normal"/>
</selector>

story_box.xml:

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

table_border.xml:

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
            <shape
        android:shape="rectangle">
                <stroke android:width="1dp" android:color="#333333" />
                <solid android:color="#EEEEEE" />
        </shape>
    </item>
</layer-list>

All the drawables are available in my project but I get this output when I try to generate signed apk:

Android resource linking failed

Output: C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_main.xml:51: error: resource drawable/search (aka uk.MyAppName.www.MyAppName:drawable/search) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_movie.xml:234: error: resource drawable/story_box (aka uk.MyAppName.www.MyAppName:drawable/story_box) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_no_internet.xml:49: error: resource drawable/retry_btn (aka uk.MyAppName.www.MyAppName:drawable/retry_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_register.xml:205: error: resource drawable/register_btn (aka uk.MyAppName.www.MyAppName:drawable/register_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_register.xml:215: error: resource drawable/register_btn (aka uk.MyAppName.www.MyAppName:drawable/register_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_search.xml:39: error: resource drawable/search (aka uk.MyAppName.www.MyAppName:drawable/search) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\search_table_item.xml:2: error: resource drawable/table_border (aka uk.MyAppName.www.MyAppName:drawable/table_border) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\table_item.xml:2: error: resource drawable/table_border (aka uk.MyAppName.www.MyAppName:drawable/table_border) not found.
error: failed linking file resources.

Command: C:\Users\MyUser.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\ac5e520165d725772f5386c054776ce5\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Users\MyUser\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
--manifest\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\merged_manifests\release\processReleaseManifest\merged\AndroidManifest.xml\
-o\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\processed_res\release\processReleaseResources\out\resources-release.ap_\
-R\
@C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\incremental\processReleaseResources\resources-list-for-resources-release.ap_.txt\
--auto-add-overlay\
--java\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\generated\not_namespaced_r_class_sources\release\processReleaseResources\r\
--proguard\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\proguard-rules\release\aapt_rules.txt\
--custom-package\
uk.MyAppName.www.MyAppName\
-0\
apk\
--output-text-symbols\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\symbols\release\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

this is my gradle file:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "uk.MyAppName.www.MyAppName"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
//            minifyEnabled false
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:exifinterface:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'org.jetbrains.anko:anko-commons:0.10.4'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.google.android.exoplayer:exoplayer:2.9.1'
}

Solution

  • To all who face this problem just change your drawable folder to drawable-v(your sdk version) hope this answer solve your problems. Or add another drawable directory with the name mentioned and simply copy your drawable files there.