Getting error says - "Entry name 'res/layout/test_toolbar.xml' collided" while creating signed apk

AndroidAndroid Studiobuild.gradleSigned ApkBuild Variant

Android Problem Overview


I have updated my android studio from 3.5.x to 3.6 today and getting an error while generating signed apk for build variant showing the following message - Entry name 'res/layout/test_toolbar.xml' collided I don't have any layout named like this one in the whole project at all. I have a custom build variant named "stage" and whenever I am trying to build a signed apk, it always fails. I count find any solution yet. Please help me with this issue. Thanks

Update: The same issue can occur with these following messages too (As I found it in AS - 3.6.1 - Continues with 4.x.x sometimes). So don't worry about these kinds of unknown and not resolvable messages. So far I found two new types of messages while generating signed apk:

  • Entry name 'kotlin/collections/MapWithDefault.kotlin_metadata' collided
  • Access Denied

The result is the same. Sometimes you may need to Invalidate Cache and Restart your AS for this. Let me know your findings. Thanks

The fast solution is: (as of the most popular answer and I agree)

  1. delete projectFolder\build delete projectFolder\debug
  2. delete projectFolder\release
  3. delete projectFolder\app\build
  4. delete projectFolder\app\build\debug
  5. delete projectFolder\app\build\release

So you need to delete all of the builds, debug and release directories.

Note that you may be not able to delete the whole debug and release directories, but you can delete all of its contents.

Android Solutions


Solution 1 - Android

Before reading the solution below, please read my update from 01.04.2020, the problem is deeper and it is in your code.

I've got the same problem after this 3.6 update.

The fast solution is:

  1. delete projectFolder\build
  2. delete projectFolder\debug*
  3. delete projectFolder\release*
  4. delete projectFolder\app\build
  5. delete projectFolder\app\build\debug*
  6. delete projectFolder\app\build\release*

So you need to delete all of the builds, debug and release directories.

Note that you may be not able to delete whole debug and release directories, but you can delete all of its contents.

UPDATE:

I think they have fixed this bug today: enter image description here

UPDATE 03.03.2020: Unfortunately, the bug doesn't fix.

UPDATE 01.04.2020: (Not 1st April joke:) )

Since month I worked with Android Studio developers and today I was told to use JDK instead of using JRE, because one of deep errors in logs said It.

After setting JDK (File->Project Structure->SDK Location->JDK Location) instead of JRE, I've got some other errors that were not shown in "build output" so I run Analyze -> Inspect Code and got EIGHTEEN errors such as referring to wrong view id in layouts, errors with orientation (hi to tools:ignore="MissingDefaultResource") and errors in manifest also with orientation: I read that this is some new update in 3.6.1 - about landscape or portrait screenOrientation, fixed fast by Studio with this: <activity tools:ignore="LockedOrientationActivity" />

When all of the errors were fixed with Analyze -> Inspect Code, I have successfully generated a signed APK using JDK and then using JRE (just for test).

So in summary, this bug caused because of deep errors which you can find out only with Inspect Code tool.

I think AS will not think that this is a bug, I think they will say that this is a new feature for improving your code. Also, I think you should try to inspect your code even without setting JDK instead of JRE.

Additional recommendation from AS support:

BTW when exporting a release build, we also run lintVital which does some extra checks and has some errors marked as fatal. This check is expensive so it does not happen in debug builds

Solution 2 - Android

I deleted the previous build outputs for the build variant, including the APK file. That's what helped me

Solution 3 - Android

Problems encountered when upgrading to the latest Android Studio 3.6.1

Clearing the cache, clean the project, and deleting the build folder did not solve the problem.


Just delete the apk generated by the previous compilation.

Solution 4 - Android

While generating the apk, check for the destination folder, from which delete output.json and app-debug.apk from debug folder. Try building the same after this. AFAIK, it is a bug for android studio, hope they might fix this soon :)

Solution 5 - Android

After updating to Android Studio 4.1 I faced similar issues, for me it was "entry name 'classes.dex' collided". The error arose when building the app using the option 'Generate Signed Bundle/APK'.

The solution was simple: make sure Android Studio is not running the app when building (stop running and then try again).

Solution 6 - Android

This issue is resolved by deleting APKs generated by the previous builds existing in release and debug folders.

Invalidating cache and rebuild would not help if you have not deleted previously generated APKs

Solution 7 - Android

I had the same error after updating android studio and I fix the problem by only cleaning the project (Build > Clean Project) !:)

Solution 8 - Android

I just delete all debug APKs in myProject\app\build\outputs\apk\debug directory and it worked for me.

Solution 9 - Android

Got a similar problem with my project after creating a signed release build and then trying to create a debug build.

To fix simply go to the menu "Build" -> "Clean Project" and then try building again.

Solution 10 - Android

This may have been overkill but I:

  1. Delete project/build folder
  2. Delete project/app/build folder
  3. File > Invalidate Caches / Restart
  4. Clean Project

Solution 11 - Android

I did an Invalidate Cache and Restart and it fixed it.

Solution 12 - Android

I had a similar issue. I have solved it by doing a "Clean Project", then a build.

Solution 13 - Android

Build and Clean Project always solves it for me. But it's a real pain.

Solution 14 - Android

It happen when you used auto viewBinding, Binding using Kotlin, or viewBinding feature of 3.6.

In case, you are adding files whose elements share the same IDs, ViewBinding confuses and creates such an error.

Let me help you by example Adapter class which has two layout file separating by view Type :

import kotlinx.android.synthetic.main.frag_subscription_recommend.view.*


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
   return ViewHolder(
        LayoutInflater.from(parent.context).inflate(
            if (viewType == 1) {
                R.layout.frag_subscription_recommend
            } else
                R.layout.frag_subscription_common,
            parent,
            false
        )
    )
}

onBinding(){
  holder.itemView.id_button_submit.setOnClickListener {}
}


 // which in case confusing which resource or layout full fill the requirement bcoz both have same ids of button.

in case you have to use :

 onBinding(){
  holder.itemView.findViewById<Button>(R.id.id_button_submit).setOnClickListener {}
}

which enables the old implementation.

Let me know if this working on your side?

Solution 15 - Android

Solved:
Just delete the earlier apk file. That's it.
Location would be: YourProjectFolder/app/debug/

Solution 16 - Android

It's due to updated configuration changes in the Gradle.

So just try File -> File > Invalidate Caches / Restart

Or Delete the old APKs in your system

Solution 17 - Android

Just Delete the ready compiled APK File even though if we delete it won't work so please delete the APK @Suraj Gupta answer is correct.

Solution 18 - Android

Delete "ProjectFolder/build" folder of your project. Make sure you Have Closed Android Studio, otherwise you would unable to delete it.

Solution 19 - Android

I got this error message while generating a signed APK.

Entry name res/interpolator/btn_checkbox_checked_mtrl_animation_interpolator_0.xml collided

Solved it by deleting the existing APK. A pretty strange solution though.

Solution 20 - Android

try to clean your build and rebuild it and then run project still did not worked then do following

File->Invalidate Cashes /restart-> Invalidate and restart

you can clean your build by

Build-> Clean project

Solution 21 - Android

The problem is build caused. The best solution is to clean and rebuild the project. Go on build and clean the project.

Solution 22 - Android

To do a clean via the CLI, run ./gradlew clean on the /android directory

That worked for me.

Solution 23 - Android

Just delete app>build and build folders in the project path on your computer!

Solution 24 - Android

All I had to do was Restart my system and go to Build > Clean Project

Solution 25 - Android

I have had these d@mned collided errors too often lately. This time I just unplugged at the computer on all four of the devices that I have been testing on. I had this... entry name 'classes.dex' collided Then I got this... BUILD SUCCESSFUL in 5s and this... APK(s) generated successfully for module 'HTMLSpyII.app' with 1 build variant: Build variant 'release': locate or analyze the APK. :) :)

Solution 26 - Android

I had the same issue. At issue' comments, I got the link to another issue, then I got a solution, which works for me.

Our project has the following lines at build.gradle(:app) specially for TeamCity

applicationVariants.all { variant ->
	variant.outputs.all {
		outputFileName = "../../" + outputFileName
	}
}

But it crashes the local build process.

So I just add condition and fix the issue!

applicationVariants.all { variant ->
	variant.outputs.all {
		if (rootProject.hasProperty("teamcity"))
			outputFileName = "../../" + outputFileName
	}
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionA S M SayemView Question on Stackoverflow
Solution 1 - AndroiddanyapdView Answer on Stackoverflow
Solution 2 - AndroidVladislav VatrushkinView Answer on Stackoverflow
Solution 3 - AndroidSuraj GuptaView Answer on Stackoverflow
Solution 4 - AndroidAmeena ShafeerView Answer on Stackoverflow
Solution 5 - AndroidLarsView Answer on Stackoverflow
Solution 6 - AndroidAkhileshView Answer on Stackoverflow
Solution 7 - AndroidAgathe Casgrain-CyrView Answer on Stackoverflow
Solution 8 - AndroidGk Mohammad EmonView Answer on Stackoverflow
Solution 9 - AndroidShubham GoelView Answer on Stackoverflow
Solution 10 - AndroidsyntakksView Answer on Stackoverflow
Solution 11 - AndroidDr. Roger WebsterView Answer on Stackoverflow
Solution 12 - AndroidJosephView Answer on Stackoverflow
Solution 13 - AndroidRotsView Answer on Stackoverflow
Solution 14 - AndroidJatin SahgalView Answer on Stackoverflow
Solution 15 - AndroidXCosmoView Answer on Stackoverflow
Solution 16 - AndroidCodemakerView Answer on Stackoverflow
Solution 17 - AndroidYugandhar VadlamudiView Answer on Stackoverflow
Solution 18 - AndroidriishiirazView Answer on Stackoverflow
Solution 19 - AndroidRamakrishna JoshiView Answer on Stackoverflow
Solution 20 - AndroidMirza Ahmed BaigView Answer on Stackoverflow
Solution 21 - AndroidSaddyView Answer on Stackoverflow
Solution 22 - AndroidFelix TooView Answer on Stackoverflow
Solution 23 - AndroidSana EbadiView Answer on Stackoverflow
Solution 24 - Androidمحمد مهدی ترکمانیView Answer on Stackoverflow
Solution 25 - AndroidMickView Answer on Stackoverflow
Solution 26 - AndroidGSD.AazView Answer on Stackoverflow