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

16

98

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.

Sabinasabine answered 26/2, 2020 at 2:49 Comment(1)
Just delete that file, and rebuild.Conway
C
152

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

Calabar answered 2/3, 2020 at 7:49 Comment(0)
I
72

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

Inflexed answered 26/2, 2020 at 14:5 Comment(2)
I tried deleting the build directory as a whole, still got the same issue. Can you elaborate what you did in full?Orangy
Are you delete build directory in root of the project and app/build directory too? In my project output path of apk is changed and I simply delete previous apk file where it was located.Inflexed
D
54

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.

Deputation answered 9/5, 2020 at 5:14 Comment(0)
G
24

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 :)

Griffen answered 27/2, 2020 at 12:35 Comment(0)
A
23

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).

Attitude answered 15/10, 2020 at 7:41 Comment(2)
Thanks for the tips ;-) For me, it was just that the phone was connectedAlleman
This worked most of the time for me (AVD instead of phone connected) but sometimes needed an additional restart of Android Studio.Insufflate
E
14

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

Endymion answered 17/9, 2020 at 17:30 Comment(0)
D
12

I had the same error after updating Android Studio.

I fixed the problem by only cleaning the project (Build > Clean Project)

Dunbar answered 11/4, 2020 at 18:55 Comment(0)
P
6

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

Pekoe answered 25/8, 2020 at 10:42 Comment(1)
Yes... Just delete the previous apk files and bob's your uncle ; )Decline
A
5

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
Atonic answered 27/7, 2020 at 15:11 Comment(0)
K
3

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?

Kotto answered 29/2, 2020 at 20:1 Comment(1)
Sorry, but the problem was with the build, debug and release directories. including output json file. Anyways, thhanks for your replySabinasabine
H
3

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

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

Harry answered 4/8, 2020 at 7:18 Comment(0)
C
1

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

Cashmere answered 5/5, 2020 at 7:7 Comment(0)
F
1

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

That worked for me.

Freshen answered 14/2, 2021 at 22:26 Comment(0)
H
1
Build 
  |-----> Clean project 
  |-----> Rebuild project

This worked for me.

Halmahera answered 8/8, 2022 at 12:48 Comment(0)
Y
0

I had entry name 'classes.dex' collided

I just unplugged at the computer all four of the devices that I have been testing on.

Then the build succeeded.

Yogurt answered 9/2, 2021 at 4:29 Comment(1)
I simply rebuilt a project and Entry name 'classes.dex' collided disappeared.Implosion
S
0

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
    }
}

Schoenburg answered 23/7, 2021 at 14:48 Comment(2)
How this fix is working? Which string is to be used as property here?Church
The fix help me to build project on TeamCity, but local build stops with error. I add the condition and apply fix only if build process is running on TeamCity.Schoenburg

© 2022 - 2024 — McMap. All rights reserved.