1

Every time I try to run the project or try to rebuild it,it throws error:failed linking resources. Please see screenshot:Error Message

All the drawable are there still it is showing this. And all the R of my java files are in red color when hover it shows a message cannot resolve symbol 'R' See screenshot: Java File Error

Error is coming in every java file I open.

I tried Invalidating caches and cleaning project but nothing is working. Search everywhere but didn't find a solution.

Thanks in advance!

EDIT: build.gradle(Module: app)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(Project:weMate)

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.shivamtiwari.wemate"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

After trying gradlew assembleDebug:

        Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

E:\MCA\AndroidProject\weMate>gradlew assembleDebug
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_account.xml:27: AAPT: error: resource drawable/uploaddisplay (aka com.shivamtiwari.wemate:drawable/uploaddisplay) not fo
und.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:9: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not fo
und.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:21: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:33: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:51: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:64: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool_list.xml:8: AAPT: error: resource drawable/list_row_selector (aka com.shivamtiwari.wemate:drawable/list_row_sel
ector) not found.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_helpdesk.xml:8: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not fo
und.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_shop_list.xml:8: AAPT: error: resource drawable/list_row_selector (aka com.shivamtiwari.wemate:drawable/list_row_selecto
r) not found.

E:\MCA\AndroidProject\weMate\app\src\main\res\layout\nav_header_main.xml:2: AAPT: error: resource drawable/side_nav_bar (aka com.shivamtiwari.wemate:drawable/side_nav_bar) not found.

error: failed linking file resources.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see aapt output above for details.

* 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

BUILD FAILED in 4s
13 actionable tasks: 1 executed, 12 up-to-date
18
  • just do FIle-->Invalidate Caches/Restart and clean and rebuild project. Commented Apr 26, 2018 at 11:55
  • As i mentioned above i have tried it several times, nothing happens Commented Apr 26, 2018 at 11:57
  • are you using custom drawable?? Commented Apr 26, 2018 at 11:59
  • have look this Commented Apr 26, 2018 at 12:01
  • Try reducing the path length for the project, meaning: Try reducing folder name - length. Commented Apr 26, 2018 at 12:05

1 Answer 1

1

In my case, After moving the resource files from Global drawable folder to specific drawable folder solved the issue.

For ex: If your resource file is in the following path

/drawable/btn_bg.xml

Then moving it to

/drawable-hdpi/btn_bg.xml 

will solve the problem.

Similarly any image files as well,

For ex: If your resource file is in the following path

/drawable/welcome_illustration.png

Then move it to

/drawable-hdpi/welcome_illustration.png
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.