I'm looking to dynamically name the APK on every build with a date/time (yyMMddHHmm). I have completed this and gradle builds and names the APK correctly, however Android Studio will not pickup the right name to attempt to push to device.
There is a question on this topic with some good info, confirming the issue and that a manual sync is required before each build. Android Studio uploads sterile APK to device when Gradle has custom logic changing APK names
For the full picture here is my build.gradle
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
// grab the date/time to use for versionCode and file naming
def date = new Date();
def clientBuildDate = date.format('yyMMddHHmm')
// for all client files, set the APK name
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, "myapp-" + versionName.replace(".","_") + "-" + clientBuildDate + ".apk")
}
}
....
defaultConfig{...}
buildTypes{...}
compileOptions{...}
signingConfigs{...}
}
The above will generate output like:
myapp-1_0_0-1507021343.apk
myapp-1_0_0-1507021501.apk
myapp-1_0_0-1507021722.apk
but Android studio will always try to load the 1st version to a phone because it is out of sync and not aware of the name change after each build.
Are there any suggestion on how to force a sync on each build/run of Android studio? Manually doing a sync before a build is a show stopper, and would require me to just go back to the default APK naming scheme.
Using: AS 1.2.1.1 & 'com.android.tools.build:gradle:1.2.3'