Fixed
Status Update
Comments
ne...@soundcloud.com <ne...@soundcloud.com> #2
I have been seeing this as well. I think it seems to be related to having the build cache enabled. (org.gradle.caching=true)
It seems that in AGP 3.4 the generated resources were put in a file named generated.xml but in the AGP 3.5 they are placed in the gradleResValues.xml file. Somehow the old output of the task is being pulled from the build cache and placed alongside the output of the new task resulting in duplicate resources. The same error occurred even after running a clean assembleDebug.
It seems that in AGP 3.4 the generated resources were put in a file named generated.xml but in the AGP 3.5 they are placed in the gradleResValues.xml file. Somehow the old output of the task is being pulled from the build cache and placed alongside the output of the new task resulting in duplicate resources. The same error occurred even after running a clean assembleDebug.
pe...@gmail.com <pe...@gmail.com> #3
Yes, any kind of clean, cleanBuildCache in command line, or clean and invalidate caches in AS have no effect on the result.
rm...@google.com <rm...@google.com> #4
Thank you for your feedback. Team may reach out for more feedback in reproducing or triaging this issue.
ne...@soundcloud.com <ne...@soundcloud.com> #5
Here's a simple repro:
Add this to an app's build.gradle.
android.defaultConfig.resValue("string", "foo", "bar")
Then change the Android Gradle Plugin from 3.4.1 to 3.5.0-beta03.
The build will fail with
Execution failed for task ':app:mergeDebugResources'.
> [string/foo] /Users/me/app/build/generated/res/resValues/debug/values/generated.xml [string/foo] /Users/me/app/build/generated/res/resValues/debug/values/gradleResValues.xml: Error: Duplicate resources.
Add this to an app's build.gradle.
android.defaultConfig.resValue("string", "foo", "bar")
Then change the Android Gradle Plugin from 3.4.1 to 3.5.0-beta03.
The build will fail with
Execution failed for task ':app:mergeDebugResources'.
> [string/foo] /Users/me/app/build/generated/res/resValues/debug/values/generated.xml [string/foo] /Users/me/app/build/generated/res/resValues/debug/values/gradleResValues.xml: Error: Duplicate resources.
je...@google.com <je...@google.com>
ne...@soundcloud.com <ne...@soundcloud.com> #6
We are currently using the following workaround:
```
afterEvaluate {
tasks.findAll {it.name ==~ "generate.*.ResValues"}.each { task ->
task.inputs.property "useAgpBeta2", (project.properties['useAgpBeta'] ?: 'false').toBoolean()
}
}
```
Where `useAgpBeta` is a project property which is set to true whenever we are using AGP 3.5 and false when we are using AGP 3.4.
```
afterEvaluate {
tasks.findAll {
task.inputs.property "useAgpBeta2", (project.properties['useAgpBeta'] ?: 'false').toBoolean()
}
}
```
Where `useAgpBeta` is a project property which is set to true whenever we are using AGP 3.5 and false when we are using AGP 3.4.
im...@google.com <im...@google.com> #7
Can you please try deleting your gradle cache? (usually located in your home directory under '.gradle' folder)
im...@google.com <im...@google.com>
im...@google.com <im...@google.com> #8
Fix pending in Change-Id: Icd1da7c69fcba7870c0508d29b95d252c0ab5739
im...@google.com <im...@google.com> #9
The fix is now in master and should be available in AGP 3.5 beta 5
Until then, deleting the app/build/generated/ directory should be enough, otherwise please *also* try deleting the .gradle cache in your home directory, and finally you can try adding a new resValue (after deleting the app/build/generated directory) to force run the generate res values task.
Until then, deleting the app/build/generated/ directory should be enough, otherwise please *also* try deleting the .gradle cache in your home directory, and finally you can try adding a new resValue (after deleting the app/build/generated directory) to force run the generate res values task.
im...@google.com <im...@google.com> #10
Please update this bug if updating to 3.5 beta 5 (once it's released) doesn't fix the issue.
di...@gmail.com <di...@gmail.com> #11
This is marked fixed, but I disagree that the issue is fully fixed, because it occurs when switching between AGP 3.5 and 3.4 in the same project, and the fix only applies in 3.5. As an example, if you have a release branch that still has AGP 3.4, building on a newer branch and then building on that release branch will fail because of the build cache.
Here's a workaround for use with 3.4:
applicationVariants.all { variant ->
tasks.named("generate${variant.name.capitalize()}ResValues").configure {
outputs.cacheIf { false }
}
}
It works by disabling the build cache for the affected task, preventing it from using the incompatible cached values added by 3.5.
Here's a workaround for use with 3.4:
applicationVariants.all { variant ->
tasks.named("generate${variant.name.capitalize()}ResValues").configure {
outputs.cacheIf { false }
}
}
It works by disabling the build cache for the affected task, preventing it from using the incompatible cached values added by 3.5.
pe...@gmail.com <pe...@gmail.com> #12
#11 is right, I just switched to a release branch with 3.4 and now I have the problem again. Duplicate resources
Description
AI-191.6707.61.35.5549111, JRE 1.8.0_202-release-1483-b02x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.14.4, screens 1680x1050, 2560x1440; Retina
AS: 3.5 Beta 2; Android Gradle Plugin: 3.5.0-beta02; Gradle: 5.4.1; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: (not found)
IMPORTANT: Please read
I'm suddenly getting this error with gradle plugin 3.5.0-beta02 (and 01), on the project which worked fine with before (3.3.x and 3.4.x):
[string/foo_account_type] /foo/build/generated/res/resValues/development/debug/values/generated.xml
[string/foo_account_type] /foo/build/generated/res/resValues/development/debug/values/gradleResValues.xml: Error: Duplicate resources
It's the same for half a dozen of such strings.
These are defined in the every flavor block in build.gradle, and used in the authenticator.xml