I am trying to check if a file exists on a certain path in android gradle
This is my code
File file = new File("../../../../releases/${version}", "${project.name}-${version}-release.aar")
if (outputFile.name.contains("debug"))
file = new File("../../../../releases/${version}", "${project.name}-${version}-debug.aar")
if (file.exists()) {
println("file found")
throw new GradleException("Aar already exists in folder $version. Change name of folder if you want the same version")
} else{println("file not found")
outputFileName = file}
It is always falling in the else case
I have tried two methods and both of them are giving false
println("file exists "+ file.getAbsoluteFile().exists())
println("file exists "+ file.exists())
The issue was due to path
File file = new File("${project.getRootDir()}/releases/${version}", "${project.name}-${version}-release.aar")
if (file.exists())
throw new GradleException("Aar already exists in folder $version. Change name of folder if you want the same version")