Android Gradle build file with Time Stamp running yesterdays version

Viewed 1660

Below I have my build file for Gradle. Issue. It runs yesterday's APK instead of today's. Root cause. I dynamically put the date in the apks name -- for debug builds.

When I run the app it sees the old APK and sees it matches what Gradle is expecting, as Gradle has not refreshed and noticed the date change.

I need to force gradle to refresh every run.

buildTypes {
   debug {
        debuggable true
        minifyEnabled false
        proguardFiles 'proguard-rules.pro'
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def formattedDate = new Date().format('yyyyMMdd')
                def newName = output.outputFile.name
                newName = newName.replace("app-", "myappname-") //"MyAppName" -> I set my app variables in the root project
                newName = newName.replace("-release", "-" + versionName + "-" + formattedDate + "-r")
                newName = newName.replace("-debug", "-" + versionName + "-" + formattedDate + "-d")
                output.outputFile = new File(output.outputFile.parent, newName)
            }
        }
    }
 }
2 Answers
Related