54

I updated Android Studio to version 2.0. The build failed and also takes longer than Android Studio version 1.5 to build. Every time I run my application, I clean and reload the project, but it's no use. The error message is:

\build\intermediates\res\resources-anzhi-debug-stripped.ap_' specified for property 'resourceFile' does not exist.

Phileo99
  • 5,581
  • 2
  • 46
  • 54
扈丽霞
  • 561
  • 1
  • 4
  • 4

8 Answers8

87

Having same issue ! So instant run is not compatible with shrinkResources

1) if use Android Studio 2.2

shrinkResources false

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled false
        shrinkResources false
        zipAlignEnabled true
        debuggable false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

2) if use Android Studio 2.0

  • open setting

  • Follow this image

  • now run your project

Parth Vora
  • 1,718
  • 13
  • 9
  • 3
    Thanks for the answer that Instant Run is not compatible with `shrinkResources`. But rather than disable Instant Run, for me the solution was to disable `shrinkResources` on my debug builds (you can leave it enabled for release builds), because I'd love to use the Instant Run feature – yuval Apr 14 '16 at 01:06
  • I disabled Instant run, but I get the same error in debug mode as well as release mode – athira09 Jul 08 '16 at 06:52
  • 2
    Didn't work for me either. Same `'resourceFile' does not exist.` error even with Instant run off on AS 2.2 preview 6. – fattire Jul 30 '16 at 07:59
  • shrinkResources false is works for me thanks @parth vora – Bhavnik Oct 27 '16 at 05:56
  • shrinkResources false isn't a solution if you want small apks. This still exists all the way to 2.3 preview... – fattire Nov 11 '16 at 21:25
  • I want to know what could be the reason for this error occurrence. – viper Mar 14 '17 at 16:37
  • I am using android studio 2.3.3.What should be done? – hitesh141 Jul 27 '17 at 06:43
  • shrinkResources false still works for android 2.3.3 to fix this build error – Francis Bacon Apr 03 '18 at 08:36
55

If you're experiencing this issue when building a release build, keep in mind that Android Plugin for Gradle 2.2.0 (and above) seems to have a bug with shrinkResources.

Downgrade gradle to 2.1.3 for a temporary solution:

classpath 'com.android.tools.build:gradle:2.1.3'

EDIT:

I reported this issue to wojtek.kalicinski (Android Developer Advocate at Google).

As it turns out, shrinkResources works only if there is minifyEnabled set to true. 2.1.3 version of Android Plugin was just ignoring the issue (and failing to shrinkResources silently). 2.2.0+ is letting you know that there is something wrong with an error (which itself isn't really informative). Google might introduce a better error message for this kind of scenarios in the future.

Here's the twitter conversation:

Community
  • 1
  • 1
Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
30

Probably you are shrinking the resources while avoiding minifying:

minifyEnabled false
shrinkResources true

If you want to shrink the resources, you have to enable minifying:

minifyEnabled true
shrinkResources true

Older versions of Build Tools were ignoring this issue, but it started throwing compilation issues on Build Tools 2.2.3

More information here: https://developer.android.com/studio/build/shrink-code.html#shrink-resources

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • 1
    I also get the same error when both `minifyEnabled` and `shrinkResources` are set to `true`. I might be mistaken but it seems the issue started either w/the upgrade to Gradle 2.3.0 or Android Studio 2.3. – Rockin4Life33 Mar 11 '17 at 21:12
  • Op, it worked for me some months ago, but probably now Build Tools changed or who know what... by the way, if you know how to fix the issue, don't hesitate to answer this question and link it to this answer :·) – Roc Boronat Mar 28 '17 at 12:48
22

Set shrinkResources to false. It worked for me

buildTypes {
    release {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable false
        jniDebuggable false
        zipAlignEnabled true
    }
}
Tommy
  • 169
  • 4
  • 16
Mable John
  • 4,518
  • 3
  • 22
  • 35
2

Found an answer, just disable instarun and it should work. It worked for me.

gregaj
  • 328
  • 1
  • 6
  • 15
1
  1. We could use both Instant Run and shrinkResources at the same time;
  2. Please be noted that we CANNOT use Jack and shrinkResources at the same time (the same to ProGuard, minifyEnabled)
Ferde
  • 75
  • 2
  • 8
1

As suggested by @Bartek-lipinski's post, I have confirmed on my own project that downgrading Gradle plugin to v2.1.3 will solve this problem of getting "InvalidUserDataException: File specified for property does not exist."

I have filed a bug with the Android tools bugtracker website, please upvote to get some more visibility on the problem.

Phileo99
  • 5,581
  • 2
  • 46
  • 54
0

In my project, because I added in the gradle shrinkResources, remove the Ok.

wyxiloveu
  • 152
  • 6