I use the code below to generate an .apk file and it works fine. But, to be able to debug I need to comment the code around "applicationVariants.all", otherwiser Android Studio says the file was not found.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def apk = output.outputFile;
def newName = "app-release-" + getDate() + ".apk";
output.outputFile = new File(apk.parentFile, newName);
}
}
}
}
How can I do to make it work for generate .apk file and also to debug on Android Studio?
UPDATE
I found what is happening, actually as I use date and time in the file name, the time in the generated file is different from the time that Android Studio tries to install.
My function getDate() returns this:
def getDate() {
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmm')
return formattedDate
}
The file created is app-release-201507110957.apk. However, in the Android Studio console, the error is:
Uploading file
local path: /Volumes/Macintosh HD/AndroidstudioProjects/App/app/build/outputs/apk/app-release-201507110956.apk
remote path: /data/local/tmp/com.domain.app
Local path doesn't exist.
The file name on generated file has 1 minute ahead than the file name Android Studio tries to install. Any idea about how I can fix that? I would like to have hour and minute in the file name because I might generate more than one version a day for QA team.