Friday, 27 August 2021

Why does having a custom name for apk leads to an error when changing target device to one with a different Android version?

The issue I have is that if I try to run my app on different devices that have different Android version I have to clean every time before changing Android versions. If I don't clean, I get the following error:

Zip file '/long path to app/app/build/outputs/app/apk/my_app_name-my_variant_name-verionName.apk' already contains entry 'some file.dex', cannot overwrite

After having this error for a long time I finally found the piece of code that is causing the problem when Android Studio Arctic Fox started telling me exactly which file had the conflict.

The gradle code that causes the problem is this:

android.applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    outputFileName = new File(path + "my_app_name-${variant.name}-${variant.versionName}.apk")
                }
            }

One solution I've found that saves me a clean is to delete the build/outputs/app directory.

So is there some way to accomplish the same thing without having this issue?



from Why does having a custom name for apk leads to an error when changing target device to one with a different Android version?

No comments:

Post a Comment